function homeSliderSlideTo(el) {
	$('div.butn').removeClass('butnactive');
	$('#butn'+el.attr('id').substr(5)).addClass('butnactive');
	$('#frontSlider li.selected').fadeOut(300, function() {
		$(this).removeClass('selected');
		el.addClass('selected');
	});
	el.css('display','block');
}
function homeSlider() {
	if($('#frontSlider li.selected').nextAll().length < 1)var next = $('#frontSlider li:first');
	else var next = $('#frontSlider li.selected').next();
	homeSliderSlideTo(next);
	}

var frontSliderInterval;
function initFrontSliderInterval() {
	frontSliderInterval = window.setInterval("homeSlider()", 3000);
}

$(document).ready(function(){
	if($('#frontSlider').length > 0) {
		initFrontSliderInterval();
	}
	
	//Flyout Menu:
	$(".mainnavitem").hover(
		function(){
			 $(this).find("span").stop().css({'display': 'none', 'height':'auto', 'overflow':'visible'}).slideDown(100);
		},
		function(){
			$(this).find("span").stop().slideUp(100);
		}
	);
	
	//Versions Slider:
	$(".versionsSlideFrame ul").css('width',$(".versionsSlideFrame ul").children().size()*380);
	//VersionsRightArrow enabled?
	if((740 - parseInt($(".versionsSlideFrame ul").css("marginLeft"))) < parseInt($(".versionsSlideFrame ul").css("width"))){
		$(".versionsArrowRight").removeClass('versionsArrowRightDisabled');
	}
	//VersionsLeftArrow enabled?
	if(parseInt($(".versionsSlideFrame ul").css("marginLeft"))<0){
		$(".versionsArrowLeft").removeClass('versionsArrowLeftDisabled');
	}
	
	$(".versionsArrowLeft").click(
		function (){
			var currmargin = parseInt($(".versionsSlideFrame ul").css("marginLeft"));
			if(currmargin < 0){
				targetMargin = currmargin + 760;
				if(targetMargin >= 0) {
					targetMargin = 0;
					$(this).addClass('versionsArrowLeftDisabled');
					}
				$(".versionsArrowRight").removeClass('versionsArrowRightDisabled');
				$(".versionsSlideFrame ul").animate({ marginLeft: targetMargin }, 350, 'swing');
			}
		}
	);
	$(".versionsArrowRight").click(
		function (){
			var maxMargin = ($(".versionsSlideFrame ul").width()*-1)+760;
			var currmargin = parseInt($(".versionsSlideFrame ul").css("marginLeft"));
			
			if(currmargin >= 0 && maxMargin < 0) {	
				targetMargin = currmargin -760;
				if(targetMargin <= maxMargin) {
					targetMargin = maxMargin;
					$(this).addClass('versionsArrowRightDisabled');
					}
				$(".versionsArrowLeft").removeClass('versionsArrowLeftDisabled');
				$(".versionsSlideFrame ul").animate({ marginLeft: targetMargin }, 350, 'swing');
			}
		}
	);
	
	//Products Slider:
	$(".productSlider ul").css('width',$(".productSlider ul").children().size()*100);
	
	//ProductsRightArrow enabled?
	if((600 - parseInt($(".productSlider ul").css("marginLeft"))) < parseInt($(".productSlider ul").css("width"))){
		$(".productSliderArrowRight").removeClass('productSliderArrowRightDisabled');
	}
	//ProductsLeftArrow enabled?
	if(parseInt($(".productSlider ul").css("marginLeft"))<0){
		$(".productSliderArrowLeft").removeClass('productSliderArrowLeftDisabled');
	}
	
	$(".productSliderArrowLeft").click(
		function (){
			var currmargin = parseInt($(".productSlider ul").css("marginLeft"));
			if(currmargin < 0){
				targetMargin = currmargin + 600;
				if(targetMargin >= 0) {
					targetMargin = 0;
					$(this).addClass('productSliderArrowLeftDisabled');
					}
				$(".productSliderArrowRight").removeClass('productSliderArrowRightDisabled');
				$(".productSlider ul").animate({ marginLeft: targetMargin }, 350, 'swing');
			}
		}
	);
	$(".productSliderArrowRight").click(
		function (){
			var maxMargin = ($(".productSlider ul").width()*-1)+600;
			var currmargin = parseInt($(".productSlider ul").css("marginLeft"));
			
			if(currmargin >= 0 && maxMargin < 0) {	
				targetMargin = currmargin -600;
				if(targetMargin <= maxMargin) {
					targetMargin = maxMargin;
					$(this).addClass('productSliderArrowRightDisabled');
				}
				$(".productSliderArrowLeft").removeClass('productSliderArrowLeftDisabled');
				
				$(".productSlider ul").animate({ marginLeft: targetMargin }, 350, 'swing');
			}
		}
	);

	
	$('.productSlider a').click(function() {
		$(this).attr('href', $(this).attr('href')+'?offset='+parseInt($(".productSlider ul").css("marginLeft")));
	});
	
	
	$("form.contentForm #leftcol input").hide();
	$(".fakecheck").css({'display' : 'inline-block'});
	$("input:checkbox").each(
		function(){
			(this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
		}
	);
	$(".fakecheck").click(
		function(){
			($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
			$("#"+this.id.substr(4)).trigger("click");
	});
	$("form.contentForm #leftcol input").change(
		function (){
			(this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
		}
	);

	
	$('#langs').hover(function() {
		$(this).addClass('hover');	
	}, function() {
		$(this).removeClass('hover');
	});

});






