/******************************************************
       Project:  Shinki Kenbukan

       Company:  BSH
     Developer:  Martin Metodiev

    Started on:  06/01/2010
    Updated on:  04/02/2010

    Sheet type:  DEFAULT Stylesheet
******************************************************/



	jQuery(document).ready(function() {

/* ........................... */
		$("div#wrapper > div.clearfix").css("margin-bottom", "90px");
		
		function maxHeight() {
			var sceneH = $(window).height();
			var bodyH = $("body").height();
			//alert("The body height is: " + bodyH + " and the scene height is: " + sceneH + ".");
			
			if(bodyH < sceneH) {
				$("body").css("height", sceneH);
			}
		}
/* ........................... */


/* ............. Content width */
		var contentWidth = $("div#content").width();

		function keepObjRatio() {
			var contentObjHeight, contentEmbHeight, objCoef, embCoef;
			contentWidth = $("div#content").width();
			$("div#content object").attr("width", "100%")
			$("div#content embed").attr("width", "100%")
			objCoef = 344 / 425;
			embCoef = 344 / 425;
			contentObjHeight = contentWidth * objCoef;
			
			if($.browser.msie) {
				contentEmbHeight = contentWidth * embCoef;
				$("div#content embed").attr("height", contentEmbHeight);
			}
			else {
				contentEmbHeight = contentWidth * objCoef;
				$("div#content object").attr("height", contentObjHeight);
				$("div#content embed").attr("height", contentObjHeight);
			}
		}
/* ........................... */

		
		maxHeight();
		keepObjRatio();
		
		jQuery(window).resize(function() {
			maxHeight();
			keepObjRatio();
		});

	});


/* .............. Random image */
	function setCookie(name, value, expires, path, domain, secure) {
	  var curCookie = name + "=" + escape(value) +
		  ((expires) ? "; expires=" + expires.toGMTString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "") +
		  ((secure) ? "; secure" : "");
	  document.cookie = curCookie;
	}
	
	function getCookie(name) {
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);
	  if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	  } else
		begin += 2;
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1)
		end = dc.length;
	  return unescape(dc.substring(begin + prefix.length, end));
	}
	
	function checkRandomNum(base, array){
		num = Math.ceil(Math.random()*base)
		for(var i=0; i<array.length; i++){
			if(Number(array[i])==num){
				checkRandomNum(base, array)
			}
			
		}
		return(num)
	}
	
	function randomNumber(){
		num = 4 //total number of images
		casheLimit = 3 //how many to keep in memory
		
		if(getCookie("randomCookie")){
			cookie_array = getCookie("randomCookie")
			cookie_array = cookie_array.split("|")
			if(cookie_array.length>=casheLimit){
				cookie_array.shift()
			}
			randomNum = checkRandomNum(num, cookie_array)
			
		}else{
			
			randomNum = Math.ceil(Math.random()*num)
			cookie_array = Array()
		}
		
		cookie_array[cookie_array.length]=randomNum
		//cookie_array.push(randomNum)
		cookiestring=""
		
		for(var i=0; i<cookie_array.length; i++){
			cookiestring +=cookie_array[i]
			if(i<cookie_array.length-1){
				cookiestring +="|"
			}
		}
		
		setCookie("randomCookie", cookiestring)
		//alert(cookie_array.toString())
		str = "<div id=\"outer_wrapper\" style=\"background: url(images/img" + randomNum + ".jpg) no-repeat center top\">"
		document.write(str)
		//alert(randomNum);
	}
/* ........................... */



/*****************************************************/