var templateImages=new Array();
templateImages[1]=new Array("mainUp.png","107334");
templateImages[2]=new Array("octapusLogo.png","3254");

var templateTotalImages=2;
var templateLoadedImages=0;
var templateTotalBytes=110588;
var templateTotalBytesLoaded=0;

$(document).ready(function(){
	$("body").append('<div id="progress"></div>');
	$("#progressbar").reportprogress(0,templateTotalBytes);
	$('body').append("<div id='cloader'></div>");
	$('#cloader').css({'position':'absolute','top':'-3000px','width':'0px','height':'1px','overflow':'hidden'});
	$('#cloader').append("<img src='images/mainUp.png' onLoad='templateCheckLoad(1);''/><img src='images/octapusLogo.png' onLoad='templateCheckLoad(2);''/>");
});
function templateCheckLoad(id){
	templateLoadedImages+=1;
	templateTotalBytesLoaded+=parseInt(templateImages[id][1]);
	$("#progressbar").reportprogress(templateTotalBytesLoaded,templateTotalBytes);
}
var showStart=0;
(function($){$.fn.reportprogress = function(val,maxVal) {var max=100;if(maxVal){max=maxVal};var width=Math.round(val/max*100);$("#progress").animate({"width":width+"%"},100,function(){if((width==100) && showStart!=1){showStart=1;$("#progress").fadeOut("slow",function(){
	startPage();
});}});}})(jQuery);

$.fn.menuClick = function(){
	$(this).click(function(){
		$clickedPageTitle = $(this).attr("id");
		if($clickedPageTitle!='111'){
			$("#midAreaText").fadeIn('fast');
			$("#menus li a").css({'color':'#727171'});
			$("#services li a").css({'color':'#873838'});
			$(this).children("a").css({'color':'#8c3a3a'});
			$.ajax({
				type: "POST",
				url: "pages/page.php?action=main&id="+$clickedPageTitle,
				success: function(data){
					if(data != ''){
						$("#textContainer").fadeOut(350, function(){
							$("#textContainer").empty();
							$("#expandableDown").animate({"minHeight":"200px"},400, function(){
								$("#textContainer").html(data);
							});
							$("#textContainer").fadeIn('slow');
						});
					}else{
						$("#textContainer").fadeOut(350, function(){
							$("#expandableDown").animate({"minHeight":"0px"},400, function(){
								$("#textContainer").empty();
							});
						});
					}
				}
			});
			$("#submenus").fadeOut(350);
			$("#ribbon").animate({"opacity":"1"},600, function(){
				$.ajax({
					type: "POST",
					url: "submenus/sub.php?action="+$clickedPageTitle,
					success: function(data){
						$("#submenus").html(data);
						$("#submenus li").subMenuClick();
					}
				});
				$("#submenus").fadeIn('slow');
			});
		}
	});
}
$.fn.subMenuClick = function(){
	$(this).click(function(){
		$("#submenus li a").css({'color':'#C69D9D'});
		$(this).children("a").css({'color':'#ffffff'});
		$clickedPageTitle = $(this).attr("id");
		$("#textContainer").fadeOut(350, function(){
			$("#textContainer").empty();
		});
		$("#expandableDown").animate({"minHeight":"200px"},600, function(){
			$.ajax({
				type: "POST",
				url: "pages/page.php?action=sub&id="+$clickedPageTitle,
				success: function(data){
					$("#textContainer").html(data);
				}
			});
			$("#textContainer").fadeIn('slow');
		});
	});
}


function startPage(){
	$("#silverDown").fadeIn(1000);
	$("#silverUp").fadeIn(1000, function(){
		$("#logo").fadeIn(1000);
		$("#languageSelectionGRSide").fadeIn(1500);
		$("#ribbon").animate({"width":"966px"}, 800, function(){
			$("#menus").fadeIn(1000);
			$("#expandableDown").animate({"minHeight":"555px"},600, function(){
				$.ajax({
					type: "POST",
					url: "pages/page.php?action=first",
					success: function(data){
						$("#textContainer").html(data);
					}
				});
				$("#textContainer").fadeIn('slow');
			});
			$("#menus li").menuClick();
			$("#services li").menuClick();
			$("#111").click(function(){
				$("#services").toggle();
			});
			$("#services").click(function(){
				$(this).toggle();
			});

			$("#footer").fadeIn(1000);
		});
	});
}

