$(document).ready(function(){
	searchSubmit();		
	toggleLang();
	updateLang();
	navHover();
	menuHover();
	slider();
})
function slider(){
	$("#sponsors #sponsorsslide").jcarousel({
		scroll: 1,
		auto: 2,
		wrap: 'last'		
	});	
}
	
function navHover(){
	$("#nav ul > li:has(ul)").children('a').append('');
	if (!$.browser.msie) {
		$('#nav>ul>li>a').not('#nav>ul>li>ul>li>a').hover(function(){
			$(this).fadeTo('fast', 1);
		}, function(){
			$(this).css({
				background: "none"
			})
			$(this).fadeTo('fast', .7);
		})
		$('#nav ul>li>ul>li>a').hover(function(){
			$(this).fadeTo('fast', .8);
		}, function(){
			$(this).fadeTo('fast', .7);
		})
		$('#footer ul li a').hover(function(){
			$(this).fadeTo(100, 1);
		}, function(){
			$(this).fadeTo(100, .4);
		})
	}
	else{
		$('#sponsors').css({
			zIndex : "-1"
		});
		$('#nav>ul>li>a,#footer>ul>li>a').not('#nav>ul>li>ul>li>a').hover(function(){
			$(this).css({
				"color" : "#333"
			})
		}, function(){
			$(this).css({
				"color" : "#666"
			})
		})
		
	}
}
function menuHover(){
	if (!$.browser.msie) {
		
		$("#nav ul > li:has(ul)").hover(function(){
			$(this).children('ul:eq(0)').fadeIn('fast');
		}, function(){
			$(this).children('ul:eq(0)').fadeOut('fast');
		})
	}
	else{
		$("#nav ul > li:has(ul)").hover(function(){
			$(this).children('ul:eq(0)').css({
				"display" : "block"
			})			
		}, function(){
			$(this).children('ul:eq(0)').css({
				"display" : "none"
			})
		})
	}
}
function searchSubmit(){
	$('#topinfo #submitbutton').click(function(){
		$('#topinfo form').submit();
	})
}
function toggleLang(){
	var current = $.cookie('lang');
	if (current==null){
		$.cookie('lang','heb')
	}
	if(current=='en'){
		$('#topinfo .boxcenter #enbutton').css({
			background : "url('/wp-content/themes/inpl/images/en.gif') no-repeat center center"
		})
		$('#topinfo .boxcenter #hebbutton').css({
			background : "url('/wp-content/themes/inpl/images/hebdisabled.gif') no-repeat center center"
		})
	}
	else {
		$('#topinfo .boxcenter #enbutton').css({
			background : "url('/wp-content/themes/inpl/images/endisabled.gif') no-repeat center center"
		})
		$('#topinfo .boxcenter #hebbutton').css({
			background : "url('/wp-content/themes/inpl/images/heb.gif') no-repeat center center"
		})
	}	
	$('#topinfo .boxcenter #enbutton').click(function(){
		current=$.cookie('lang');
		if (current != 'en'){
			$.cookie('lang','en');
			$(this).css({
				background : "url('/wp-content/themes/inpl/images/en.gif') no-repeat center center"
			})
			$('#hebbutton').css({
				background : "url('/wp-content/themes/inpl/images/hebdisabled.gif') no-repeat center center"	
			})
			if (!$.browser.msie) {
				updateLang();
			}
			else {
				window.location.reload();				
			}
		}
	})
	$('#topinfo .boxcenter #hebbutton').click(function(){
		current=$.cookie('lang');		
		if (current != 'heb'){
			$.cookie('lang','heb');
			$(this).css({
				background : "url('/wp-content/themes/inpl/images/heb.gif') no-repeat center center"
			})
			$('#enbutton').css({
				background : "url('/wp-content/themes/inpl/images/endisabled.gif') no-repeat center center"	
			})
			
			if (!$.browser.msie) {
				updateLang();
			}
			else {
				window.location.reload();				
			}

		}
	})
}

function updateLang(){
	if ($.cookie('lang')==null || $.cookie('lang')=="en"){
		$('.heb').hide();
		$('.en').fadeIn('fast');
		$('#enbutton').css({
				background : "url('/wp-content/themes/inpl/images/en.gif') no-repeat center center"	
			})
		$('#hebbutton').css({
				background : "url('/wp-content/themes/inpl/images/hebdisabled.gif') no-repeat center center"	
			})		
	}
	else {
		$('.en').hide();
		$('.heb').fadeIn('fast');		
		$('#enbutton').css({
				background : "url('/wp-content/themes/inpl/images/endisabled.gif') no-repeat center center"	
			})
		$('#hebbutton').css({
				background : "url('/wp-content/themes/inpl/images/heb.gif') no-repeat center center"	
			})
	}
}
