if (document.all){
	// ie6 sp2 checking	
	(function(){ var  m = document.uniqueID  && document.compatMode && !window.XMLHttpRequest && document.execCommand; try{ if(!!m){m("BackgroundImageCache", false, true)}}catch(oh){};})();
}

function is_ajax() {
	if (window.XMLHttpRequest) {
        return true;
    } else if (window.ActiveXObject) {
		return true;
   }
   return false;
}
	

easing = null;
speed = 200;
	
function getAnchor(){ 
	if(typeof location.hash != undefined) {
		var name = location.hash.split("#"); 
		return name[1];	
	} 
	return false; 
}


function parseUrl(l,p){
	if (typeof currentpage == 'undefined') return true;
	if (p != currentpage){
		clearInterval(AjaxMonitorInterval);
		
		res = l.toString().indexOf('page=');
		if (res != -1){
			parts = l.toString().split('page=');
			var urlz = parts[0] + 'page='+ parts[1].replace(/^\d+/, p)
		} else {
			var name = l.toString().split("#"); 
			var urlz = name[0]+'?page='+p;
		}
		pageloadajax(urlz);
	}
}

function AjaxMonitor(){
	if ( page = getAnchor()){
		if (typeof currentpage == 'undefined') return true;
		if (page != currentpage){
			parseUrl(location,page);
		}	
	}

}

AjaxMonitorInterval = setInterval(AjaxMonitor, 500);

$(window).ready(function(){
	if (page = getAnchor()){
		parseUrl(location,page);
	} else {
		if (typeof currentpage == 'undefined') return true;
		n = location.toString().split('#');
		window.location.href = n[0]+'#'+currentpage;
	}
});


 function Minimize()
{
window.innerWidth = 100;
window.innerHeight = 100;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
}

function Maximize()
{
window.innerWidth = screen.width;
window.innerHeight = screen.height;
window.screenX = 0;
window.screenY = 0;
alwaysLowered = false;
}
	
function pageloadajax(url){
 		clearInterval(AjaxMonitorInterval);
	$.get(  
		'/en/ajax/paged/', 
		{ url : url } ,
		function(xml){
							
				

					if ($.browser.msie && $.browser.version == '8.0'){
							 
							$('.cont').html($('content', xml).text());
					
							
							
							if (location.toString().indexOf('xhtml') != -1){
								if (mlc()){
									
									$('.cont').html(
										'<div id="contentblock"><div id="article" class="article">'+
										'<div class="leftcolumn">'+ $('.leftcolumn').html()+'</div>'+
										'<div class="rightcolumn">'+$('.rightcolumn').html() +'</div>'+										
										'<div class="c"></div></div></div>' + 			
										'<div class="paged">'+$('.paged').html()+'</div>'
									);
									$('.cont').css({position:'relative'});
									$('.cont').parent().parent().css({height:($('.cont').height()+40)});
									top.window.resizeTo(screen.availWidth-1,screen.availHeight-1);	
									top.window.resizeTo(screen.availWidth,screen.availHeight);			
								}
									
							} else {
								$('.pad20top').css({marginTop:'-50px'});
							}
						 
							hover();clickit();newsitem();
							currentpage = $('page', xml).text();

							AjaxMonitorInterval = setInterval(AjaxMonitor, 500);
							n = location.toString().split('#');
							window.location.href = n[0]+'#'+currentpage;
						 	$.scrollTo('#top', 250);
							previewActivate(currentpage);
							return false;
					}
					
					if ( $('page', xml).text() > currentpage){
				
						$('#contentblock').animate({ left: -$('#contentblock').width() }, speed, easing, function(){
							$('.cont').html($('content', xml).text());
							if (mlc()){
								$('#contentblock').css({left:+$('#contentblock').width(), right:+(2*$('#contentblock').width())});
								$('#contentblock').animate({left : 0 }, speed, easing);						
								hover();clickit();newsitem();
							} else{
								hover();clickit();newsitem();	
							}
						});	
						
					} else{
						$('#contentblock').animate({left:$('#contentblock').width(),right:(2*$('#contentblock').width()) }, speed, easing, function(){
							$('.cont').html($('content', xml).text());
							if (mlc()){
								$('#contentblock').css({left:-$('#contentblock').width(),right:-(2*$('#contentblock').width())});
								$('#contentblock').animate({  left : 0 }, speed, easing);
								hover();clickit();newsitem();	
							} else {
								hover();clickit();newsitem();	
							}
						});
					}
					currentpage = $('page', xml).text();	
					previewActivate(currentpage);
					AjaxMonitorInterval = setInterval(AjaxMonitor, 500);
				 	n = location.toString().split('#');
					window.location.href = n[0]+'#'+currentpage;
				 	$.scrollTo('#top', 250);					
				}	   
		);
}	
	
function clickit(){

jQuery('.paged a').bind('click', function(){
		if ($(this).attr('href') == null) return false; 
		
		if (!is_ajax()){
	 		window.location.href = $(this).attr('href');
		} else {
			pageloadajax($(this).attr('href'));
			return false;
		}
		return false;

	});
}

function previewActivate(id){

	
	if ($('#title_'+id).length == 1){
		prevurl = $('#titleimages').find('.titleimage').filter(':visible').css('background-image');
		if ($('#titleimages').find('.titleimage').filter(':visible').length > 0){
			if (prevurl == $('#title_'+id).css('background-image')){
				$('#titleimages').find('.titleimage').filter(':visible').css('display', 'none');
				$('#title_'+id).css('display', 'block');				
			} else {
				$('#titleimages').find('.titleimage').filter(':visible').fadeOut(500, function(){
					$('#title_'+id).fadeIn(500);
				});
			}
		} 
	} 	
}

jQuery(window).ajaxStart(function(){
	$('body').append('<div id="jquery-overlay">&nbsp;</div>');
	var arrPageSizes  = LightBox_getPageSize();
	var arrPageScroll = LightBox_getPageScroll();
	
	
	if (($.browser.msie && $.browser.version == '8.0') || ($.browser.opera && $.browser.version > 9)){
		var height = (arrPageScroll[1]+((arrPageSizes[3]/2)-50));		
		$('#jquery-overlay').css({
			width:arrPageSizes[0]+'px', 
			height:(arrPageSizes[1]+arrPageScroll[1])+'px'
		});
		
		if ($.browser.opera){
			$('#jquery-overlay').css({
				background:'#ccc url(/d/i/load2.gif) no-repeat center '+height+'px',
				opacity:0.5
			});
		} else {
			$('#jquery-overlay').css({
				background:'url(/d/i/load2.gif) no-repeat center '+height+'px'									 
			});
		}
	} else {
		var height = (arrPageScroll[1]+((arrPageSizes[3]/2)-50));
		$('#jquery-overlay').css({
			background:'#cccccc url(/d/i/load2.gif) no-repeat center '+height+'px', 
			opacity:0.5,
			width:arrPageSizes[0]+'px', 
			height:arrPageSizes[1]+'px'
		});
	}

});


jQuery(window).ajaxComplete(function(){
   	 $('#jquery-overlay').remove();
});

jQuery(window).ready(function(){ 
							  
	$('.loginbox').css('display', 'none');
	$('.singupbox').css('display', 'block');
	
	$('#renko').bind('click', function(){
		$('.loginbox').css('display',  ( $('.loginbox').css('display')  == 'block' ? 'none':'block') );
		$('.singupbox').css('display', ( $('.singupbox').css('display') == 'block' ? 'none':'block') );
		return false;
	});
	clickit();
	hover();
	newsitem();
});

var lastmark = readCookie('lastmark') ? readCookie('lastmark') : 14;

function mlc(){
	 
	if ($('.Article').length != 1) return true;
	
	if (($.browser.mozilla && $.browser.version >= '1.5') || ($.browser.safari)) {  
		return true;
	}
	
	 
	if ($.browser.msie && $.browser.version != '8.0' && typeof frames['multicolumns'].fix == 'function')	{
		$('#multicolumns').contents().find('.Article').html(' ').css({width:'620px'});											   
		$('#multicolumns').contents().find('.Article').html( $('#Article').html() );											   
		frames['multicolumns'].fix();
	} else {

		if (typeof frames['multicolumns'].fix == 'function'){
			$('#multicolumns').contents().find('.Article').html(' ').css({width:'620px'});											   
			$('#multicolumns').contents().find('.Article').html( $('#Article').html() );											   
			frames['multicolumns'].fix();				
		}
	}
	 
	return true;
}



function newsitem(){
	setTimeout(function(){
		initfs();
		clearTimeout();
	}, 200); 
	
	

		
	
	if ($('.newsitemrecord').length > 0){
		 
		
		$('.newsitemrecord strong.openclose').bind('click.u', function(){
			
			if ($('.long', $(this).parent()).css('display') == 'none'){
				
				$('.short', $(this).parent()).css({display:'none'});
				$('.long', $(this).parent()).css({display:'block'});		
				
			} else {
					
				$('.short',$(this).parent()).css({display:'block'});
				$('.long',$(this).parent()).css({display:'none'});
				
			}
			return false;
		});	
		

		$('.newsitemrecord span.openclose').bind('click.u', function(){
			if ($('.long', $(this).parent().parent()).css('display') == 'none'){
				$('.short', $(this).parent().parent()).css({display:'none'});
				$('.long', $(this).parent().parent()).css({display:'block'});		
			} else {
					
				$('.short',$(this).parent().parent()).css({display:'block'});
				$('.long',$(this).parent().parent()).css({display:'none'});
			}
			return false;
		});	
		
	}
}

function hover(){ 	
	jQuery('.spec').each(function(){
		jQuery(this).bind('click', function(){
			window.location.href = $('a.catch', this).attr('href');
		});
	});
	
	if ($.browser.msie && $.browser.version == '6.0'){
		jQuery('.spec').hover(function(){jQuery(this).addClass('hover');},function(){jQuery(this).removeClass('hover');});
	}
}

 

function initfs(){
		val = readCookie('step') ? readCookie('step') : '12';
		$('.fontsize').css('fontSize', val+'px');
		$('.fontsize *').each(function(){
			$(this).css('fontSize', val+'px');
		});
}
function font(id){
	createCookie('step',id)
	initfs();
}
function printer(dep,id){
	$.get(
		'/en/ajax/print/'+dep+'/'+id,
		{},
		function(xml){
			parent.frames[0].document.title = $('title', xml).text(); 
			parent.frames[0].document.getElementById('header').innerHTML = $('title', xml).text();
			parent.frames[0].document.getElementById('content').innerHTML = $('content', xml).text();
			if ($.browser.msie == true){
				iframe.focus();
				iframe.print(); 
			} else {
				parent.frames[0].window.print();
			}
			//document.getElementsByTagName('iframe')[0].contentWindow.print();
			
		}
	);
}

function getHeight(obj){
	return obj.offsetHeight;
}

function createCookie(name,value,days) {
	if (!days)  days  = 10;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
			createCookie(name,c.substring(nameEQ.length,c.length));
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
} 