var shown = 0;
$(document).ready(function() {
	//set easing
	$.easing.def = 'easeInOutQuart';
	
	if($(".scrollable").length) {
		//initialize scrollable together with the navigator plugin
		$(".scrollable").each(function() {
			if($(this).find("img").length>1) $(this).scrollable({circular: true}).navigator();
			else $(this).find(".prev, .next").hide();
		});
	}
	$("#splashContent").height($(window).height());
	$("#splashContent").width($(window).width());
	$("#sidebar").height($(window).height());
	$("#htmlContent").width($(window).width()-334);
	
	if($("body").hasClass("mobile")) {
		if(window.orientation == 0 || window.orientation == 180) $("body").addClass("portrait");
		window.onorientationchange = orientationChange;
		if(!$("body").hasClass("portrait") && $("#htmlcontent").height()<$(window).height()) $("#htmlcontent").height($(window).height());
	}
	
	if($(".mobile #splashContent").length>0) {
	} else if($("#splashContent").length>0) slideAnimation();
	else {
		//navigation
		$('#menu').tabs('#menu ul.pane', {
			tabs: '.accordion-tabs',
			effect: 'slide',
			initialIndex: null,
			onClick: function() {
				window.location = $(".heading.current").attr("href");
			}
		});
		
		//add class to show current page
		$('.pane a').click(function() {
			$('.pane a.active').removeClass('active');
			$(this).addClass('active');
		});
		
		//navigation background switching
		$('.group1').click(function() {								
			if(shown != 1) {
				//move left
				$('#i1').animate({'left': '0px'}, 500);
				//move right
				$('#i2, #i3, #i4, #i5, #i6').animate({'left': '292px'}, 500);
				shown = 1;
			}
		});
		$('.group2').click(function() {
			if(shown !=2) {						
				if(shown > 2) {
					//move left
					$('#i1, #i2').animate({'left': '0px'}, 500);
					//move right
					$('#i3, #i4, #i5, #i6').animate({'left': '292px'}, 500);
				}  else {
					//move left
					$('#i1, #i2').animate({'left': '0px'}, 500);
					//move right
					$('#i3, #i4, #i5, #i6').animate({'left': '292px'}, 500);
				}
				shown = 2;
			}
		});
		$('.group3').click(function() {
			if(shown != 3) {								
				if(shown > 3) {	 
					//move left
					$('#i1, #i2, #i3').animate({'left': '0px'}, 500);
					//move right
					$('#i4, #i5, #i6').animate({'left': '292px'}, 500);
				}  else {
					//move left
					$('#i3').animate({'left': '0px'}, 500);
					//move right
					$('#i4, #i5, #i6').animate({'left': '292px'}, 500);
				}
				shown = 3;
			}
		});
		$('.group4').click(function() {
			if(shown != 4) {
				if(shown > 4) { 
					//move right
					$('#i1, #i2, #i3').animate({'left': '0px'}, 500);
					//move left
					$('#i5, #i6').animate({'left': '292px'}, 500);
				} else {
					//move right
					$('#i5, #i6').animate({'left': '292px'}, 500);
					//move left
					$('#i2, #i3, #i4').animate({'left': '0px'}, 500);
				}
				shown = 4;				
			}
		});
		$('.group5').click(function() {
			if(shown != 5) {
					//move left
					$('#i1, #i2, #i3, #i4, #i5').animate({'left': '0px'}, 500);
					//move right
					$('#i6').animate({'left': '292px'}, 500);
			}
			shown = 5;
		});
		$('.group6').click(function() {
			if(shown != 6) {
				// move left
				$('#i1, #i2, #3, #i4, #i5, #i6').animate({'left': '0px'}, 500);
			}
		});							
	}
	
	//company "more" button
	$('a#more').click(function() {							   
		$('.hidden').slideDown();
		$('a#more').hide();		
		return false;											
	});
	
	$("#overlay").overlay({mask:{ color:'#000000', opacity:0.75 }, left:'center', top:'center', load:true });
});
$(window).resize(function() {
	$("#splashContent").height($(window).height());
	$("#splashContent").width($(window).width());
	$("#sidebar").height($(window).height());
	$("#htmlContent").width($(window).width()-334);
	if($(".mobile #splashContent").length>0) {
	} else if($("#splashContent").length>0) slideAnimation();
});

function moveLeft(selector) {
	$(selector).animate({'left': '0px'}, 500);
}
function moveRight(selector) {
	$(selector).animate({'left': '292px'}, 500);
}
function orientationChange() {
	if(window.orientation == 0 || window.orientation == 180) $("body").addClass("portrait");
	else $("body").removeClass("portrait");
	$("#splashContent").height($(window).height());
	$("#splashContent").width($(window).width());
	$("#sidebar").height($(window).height());
	$("#htmlContent").width($(window).width()-334);
}
function showIframe() {
	document.getElementById('archLoading').style.display="none";
	$("#shrFrm").fadeIn("slow");
}
function slideAnimation() {
	$(".column.active").removeClass("active");
	var splashAnimationSpeed = 500;
	if($(window).width() < 1024) {
		$('#splashContent').width(1024);
		initialColumnWidth = 246; // Calculation is (1024 - 40) / 4 
	} else {
		$("#splashContent").width($(window).width());
		initialColumnWidth = ($(window).width()-40) / 4;
	}
	var slideArea = $("#splashContent").width();
	var column1Pos = 40;
	var column2Pos = 40 + initialColumnWidth;
	var column3Pos = 40 + (2*initialColumnWidth);
	var column4Pos = 40 + (3*initialColumnWidth);
	$('#splash div').css("width","900px");
	$('#column1').css("left",column1Pos);
	$('#column2').css("left",column2Pos);
	$('#column3').css("left",column3Pos);
	$('#column4').css("left",column4Pos);
	
	var alteredColumnLarge = 1.25*initialColumnWidth;
	var alteredColumnSmall = ($('#splashContent').width()-40-alteredColumnLarge) / 3;
	$('.column').width(alteredColumnLarge);
	$('#column4').width(alteredColumnLarge + 40);
	
	$('#column1').hover(function() {
		if($("#splash_input").is(":focus")) return false;
		$(".column.active").removeClass("active");
		$(this).addClass("active");
		$('#column2').animate({'left' : alteredColumnLarge + 40 +'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column3').animate({'left' : alteredColumnLarge + alteredColumnSmall + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column4').animate({'left' : alteredColumnLarge + (2 * alteredColumnSmall) + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
	});
	$('#column2').hover(function() {
		if($("#splash_input").is(":focus")) return false;
		$(".column.active").removeClass("active");
		$(this).addClass("active");
		$('#column2').animate({'left' : alteredColumnSmall + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column3').animate({'left' : alteredColumnSmall + alteredColumnLarge + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column4').animate({'left' : (2 * alteredColumnSmall) + alteredColumnLarge + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
	});
	$('#column3').hover(function() {
		if($("#splash_input").is(":focus")) return false;
		$(".column.active").removeClass("active");
		$(this).addClass("active");
		$('#column2').animate({'left' : alteredColumnSmall + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });		
		$('#column3').animate({'left' : (2 * alteredColumnSmall) + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column4').animate({'left' : (2 * alteredColumnSmall) + alteredColumnLarge + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
	});
	$('#column4').hover(function() {
		if($("#splash_input").is(":focus")) return false;
		$(".column.active").removeClass("active");
		$(this).addClass("active");
		$('#column2').animate({'left' : alteredColumnSmall + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });		
		$('#column3').animate({'left' : (2 * alteredColumnSmall) + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
		$('#column4').animate({'left' : (3 * alteredColumnSmall) + 40 + 'px'}, { duration: splashAnimationSpeed, queue:false });
	});
}
