var left_=0;
var l_=0;
var left_2=0;
$(document).ready(function(){
	menu();
	showRum();
	makeScroll('');
	popWinX();
});
function makeScroll(){
	if($('#popWinBox2').html()==null && $('#popWinBox3').html()==null){
		if($('#tableBoxRightSectionvideos').html()){
			mySelect('cookVideo');
			$('.videoList:visible').eq(0).css('padding',0);
			myScroll = new ScrollObj(3,12,339,"track","up","down","drag","scrollerContainer","scrollerContent");		
		}else if($('#tableBoxRightSectionpublications').html()){
			mySelect('cookPub');
			$('.publicationsList:visible:first').css('padding','0 0 27px');
			$('.publicationsList:visible:last').css({'padding':'26px 0 0','border-bottom':'none'});
			myScroll = new ScrollObj(3,12,364,"track","up","down","drag","scrollerContainer","scrollerContent");		
		}else if($('#tableBoxRightSectionpress').html()){
			mySelect('cookPress');
			$('.pressList:visible:first').css('padding','0 0 27px');
			$('.pressList:visible:last').css({'padding':'26px 0 0','border-bottom':'none'});
			myScroll = new ScrollObj(3,12,339,"track","up","down","drag","scrollerContainer","scrollerContent");		
		}
	}
}
function popWinX(){
	$(".popWinX").fancybox({
		'centerOnScroll' : true,
		'width'				: 560,
		'height'			: 430,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding' :0,
		'margin' : 0,
		//'overlayShow'	: false,
		'overlayOpacity' : 0.3,
		'overlayColor' : '#fff',
		'transitionIn'	: 'elastic',
		'showCloseButton' : false,
		'transitionOut'	: 'elastic',
		'onClosed':function(){
			//if(refreshCheck) location.href='./';
		}
	});
	
	$(".popWinX2").fancybox({
		'centerOnScroll' : true,
		'width'				: 587,
		'height'			: 440,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding' :0,
		'margin' : 0,
		//'overlayShow'	: false,
		'overlayOpacity' : 0.3,
		'overlayColor' : '#fff',
		'transitionIn'	: 'elastic',
		'showCloseButton' : false,
		'transitionOut'	: 'elastic',
		'onClosed':function(){
			//if(refreshCheck) location.href='./';
		}
	});
	
	$(".popWinX3").fancybox({
		'centerOnScroll' : true,
		'width'				: 545,
		'height'			: 380,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding' :0,
		'margin' : 0,
		//'overlayShow'	: false,
		'overlayOpacity' : 0.3,
		'overlayColor' : '#fff',
		'transitionIn'	: 'elastic',
		'showCloseButton' : false,
		'transitionOut'	: 'elastic',
		'onClosed':function(){
			//if(refreshCheck) location.href='./';
		}
	});
	
	$(".popWinX").click(function(){
		return false;
	});
	
	$('#closeParentFancyBox').click(function(){
		 parent.$.fancybox.close();
		 return false;
	});
	
	$('.iframeA').attr('target','_top');
}

function mySelect(cook){
	//$('.filterList').removeClass('showYesHodfords');
	if(getCookie(cook)){
		$('.filterList').hide();
		var val=getCookie(cook);
		var arr=null;
		$('.filterList').each(function(index){
			arr=$(this).attr('value').split(',');
			if(arr.length){
				for(var i=0;i<arr.length;i++){
					if(val==arr[i]){
						$(this).show();
						//$('.filterList').addClass('showYesHodfords');
					}
				}
			}
		});
		//$('.filterList[value="'+getCookie(cook)+'"]').show();
		$('#searchKey').attr('value',val);
	}else{
		$('.filterList').show();
		//$('.filterList').addClass('showYesHodfords');
	}
	$('#searchList > a').click(function(){
		var val=$('#searchKey').attr('value');
		setCookie(cook,val);
		location.reload(); 
		return false;
	});
}
function menu(){
	$('.menuArtMouseOver').hover(
		function(event){
			$('#tableBox').css('z-index','-100');
			$('.headertable').css('z-index','100');
			$('.headertable').next('table').css({'z-index':'-100','position':'relative'});
			$(this).find('div').show();	
			event.stopPropagation();
		}
		, 
		function(event){
			$(this).find('div').hide();	
			$('#tableBox').css('z-index','1');
			$('.headertable').css('z-index','auto');
			$('.headertable').next('table').css({'z-index':'auto','position':'static'});
			event.stopPropagation();
		}
	);
}

function showRum(){
	left_=parseInt($('#tableCom').css('left'));
	l_=parseInt($('#tableCom').width());
	showIco();
	$('#listnext > a').click(function(){
		$('#listback').hide();
		$('#listnext').hide();
		left_2-=1000;
		left_-=976;
		$('#tableCom').animate({left: left_+'px'}, 500,'linear',function(){showIco();});
		return false;
	});
	$('#listback > a').click(function(){
		$('#listback').hide();
		$('#listnext').hide();
		left_2+=1000;
		left_+=976;
		$('#tableCom').animate({left: left_+'px'},500,'linear',function(){showIco();});
		return false;
	});
}

function showIco(){
	$('#listback').hide();
	$('#listnext').hide();
	if(parseInt(l_+left_2)>1000){
		$('#listnext').show();
	}
	if(parseInt(left_)<0){
		$('#listback').show();
	}
}

function setCookie(name,value){
	var exp  = new Date(); 
    exp.setTime(exp.getTime() + 3*60*1000);
    document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
}
function getCookie(name){
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

