// JavaScript Document

$(function(){
		   
	//door and bannerfade
	var img = [];
	for(i=0; i<7;i++){			
	img[i] = "url(images/" + (i+1) +"w.png)";			
	$('#banner').prepend('<div class="banner_bg">');
	}
	j =0;
	k = 7;
	$('.banner_bg').each(function(){
		$(this).css({'z-index':k,'background-image':img[j] })						  
		k--;
		j++;
	});
	$('.l_1').width(($(window).width()/2)+1).height(($(document).height()-30));
	$('.r_1').width(($(window).width()/2)+1).height(($(document).height()-30));
	$('#banner_in').css({ left:($(window).width() - $('#banner_in').width())/2});
	$('#banner_bg').css({ left:($(window).width() - $('#banner_bg').width())/2});
 
	$('#mask_1').width($(document).width()).height($(document).height());
	$('#loader').width($(window).width()).height($(window).height());			
	
	cook();
	var v;
	function cook(){
		v = checkCookie();
		}
	if(v=="last"){
		$(window).load(function(){	 			
		$('#mask_1').remove();					
		$('.door_1').start({time:5000, speed:1500,opendoor:1500,fadespeed:1000});
		});
	}
	else{
		$('#mask_1').remove();					
		$('.door_1').width(0).height(0);
		$('.door_1').children().width(0).height(0);
		$('.door_1').start({time:5000, speed:1500,opendoor:1500,fadespeed:1000,repeat:true});
		}
	if($('body').children('div.door_1').length ==0){
		$('body').prepend('<div class="temp"></div>	');
		$('.temp').start({time:5000, speed:1500,opendoor:1500,fadespeed:1000,repeat:true});
		$('.temp').remove();
		}
	
	$(window).resize(function(){
	 	$('#banner_in').css({ left:($(window).width() - $('#banner_in').width())/2});
		$('#banner_bg').css({ left:($(window).width() - $('#banner_bg').width())/2});
		  
	  });

});




function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("call_door");
if (username!=null && username!="")
  {  
  return username;
  }
else 
  {
   username = "first";     
   if (username!=null && username!="")
    {
    setCookie("call_door",username,365);
    }
   return "last";	
  }
}
