var clickdet = 0;
var clickdeto = 0;
var flag=0;
var gheight;
$(document).ready(

function(){
gheight = $(document).height();
$('#container').not($('.cat')).click(
function(){
closePopUp();
});
$("#closeonclick").css({"display":"none","width":"99%","height":gheight,"position":"absolute","top":"0","left":"0"});
$("#closeonclick").click(
function(){

$("#closeonclick").css({"display":"none","width":"99%","height":gheight});
closePopUp();
}
);


$('.cat').bind('dblclick',function(){/*NOthingg to be done*/});

$('.cat').css('cursor','pointer');
$('document:not(div)').click(
function(){
//alert("NOT CLICKED");
closePopUp_2();
}
);

/*****
$('.cat').hover(
function(e){
var id=e.target.id;
console.log(id);
elem = document.getElementById(id);
$(elem).css('border','rgba(100,0,0,0)');
$(elem).css('filter','alpha(opacity = 85)');
$(elem).css('opacity','.85');

//$("#popup_container").css('filter','alpha(opacity = 80)');
}
,
function(e){
var id=e.target.id;
console.log(id);
elem = document.getElementById(id);
$(elem).css('border','none');
$(elem).css('filter','alpha(opacity = 100)');
$(elem).css('opacity','1');

//$("#popup_container").css('filter','alpha(opacity = 80)');
}
);***/

}
);


var old_id;

function openPopUp(id,top,left,width,height){
//alert("click");
$('.cat').css("z-index","110");
$("#popup_container").css({"z-index":"112"});
//$("#closeonclick").css({"z-index":"0","display":"block"});
if(clickdeto==0){
clickdeto = 1;
openpopUpact(id,top,left,width,height);
setTimeout(function(){clickdeto = 0},500);
}
else{
return;
}
}
function openpopUpact(id,top,left,width,height){
//issopen = id;
  if(flag==0){
  top=top;
  left=left+125;
//   $("#popup_bg").fadeIn();


  //var bg="url(\"http://www.shaastra.org/2011/media/main/img/"+id+"_copy.png\")";					//change no 1
  var bg="url(\"http://www.shaastra.org/2011/media/main/img/ctbg.png\")";
  
  
  $("#popup_container").css({"width":width,"height":height,"background":bg});
  var e=document.getElementById("popup_container");
	e.style.left=left+"px";
	e.style.top=top+"px";
	e.style.display="block";
	$("#popup_container").fadeOut(0);


	setTimeout(function(){
	$("#popup_container").show("fold",{},1000);
	},0);
  flag=1;
  old_id="#"+id+"_contents";
$(old_id).hide();
  old_id="#"+id+"_contents";
  load_contents(id);
}
  else
	slide(id,top,left,width,height);
}
function closePopUp_2(){

  $(old_id).fadeOut(200);
  setTimeout(function(){$("#popup_container").hide();},300);
  flag=0;
}

function closePopUp(){
	$("#closeonclick").css({"display":"none","width":"99%","height":gheight,"position":"absolute","top":"0","left":"0"});

	$("#popup_container").fadeOut(300);
  
  setTimeout(function(){$(old_id).hide();$("#popup_container").hide();},300);
  flag=0;
}

function loadAnimated(){
  $("#impact").animate({"width":"253px","height":"189px"},600);
}

function slide(id,top,left,width,height){
if(clickdet==0){
clickdet = 1;
slideact(id,top,left,width,height);
setTimeout(function(){clickdet = 0},500);
}
else{
return false;
}
}

function slideact(id,top,left,width,height){
	
  if(flag==1){
  var top_p = document.getElementById('popup_container').style.top;
  var left_p = document.getElementById('popup_container').style.left;
  //$(old_id).css('filter','inherit');
  $("#popup_container").fadeOut(500);
  
  setTimeout(function(){
  top=top;
  left=left+125;
    
    //$("#popup_container").show("fold",{},200);
	//document.getElementById('popup_container').style.top  = top_p;
	//document.getElementById('popup_container').style.left = left_p;
	$("#popup_container").hide();
	//$("#popup_container").css('opacity','1');
	$(old_id).show();
  //var bg="url(\"http://www.shaastra.org/2011/media/main/img/"+id+"_copy.png\")";					//change no 1
  var bg="url(\"http://www.shaastra.org/2011/media/main/img/ctbg.png\")";
  
  
  $("#popup_container").stop().css({"width":width,"height":height,"background":bg});
  var e=document.getElementById("popup_container");
	e.style.left=left+"px";
	e.style.top=top+"px";
	e.style.display="block";
	//$("#popup_container").hide();
	//$("#popup_container").hide("slide",{direction:'right'},100);
	setTimeout(function(){
	if(!IE_)         $("#popup_container").css('opacity','1');   
	      
         //$("#popup_container").css('filter','alpha(opacity=100)');
	$("#popup_container").show("fold",{},1000);
	},0);
$(old_id).hide();
  old_id="#"+id+"_contents";
  load_contents(id);
},500);
}
}

function load_popup(){
	$('#cen').fadeIn(1500); 
  $("#footer_container").css({"position":"absolute","top":"593px"});  
    $("body").css({"overflow":"hidden"});
  $("#content").animate({"left":"-1200px"},600);
  $("#container1").show().animate({"left":"125px"},600);
//   $("#content").hide();
  $("#right_arrow").fadeOut();
  $("#left_arrow").fadeIn();
  $("#content").fadeOut();
  setTimeout(function(){$("body").css({"overflow":"auto"});},600);
}

function close_popup(){
  closePopUp();
 $('#cen').hide();
  $("#footer_container").css({"position":"relative","top":"0px"});  
    $("body").css({"overflow":"hidden"});
  $("#content").show().animate({"left":"0px"},600);
  $("#container1").animate({"left":"1200px"},600).fadeOut();
  $("#right_arrow").fadeIn();
  $("#left_arrow").fadeOut();
  setTimeout(function(){$("body").css({"overflow":"auto"});},1000);
}

function load_contents(id){
  $("#"+id+"_contents").fadeIn();
  
 // $("#catimage").html("<img src=\"http://www.shaastra.org/2011/media/main/img/cat/"+id+".jpg\" />");  
  $("#catimage").html("<img src=\"http://www.shaastra.org/2011/media/main/img/cat/catmaster.jpg\" />");
 
 
  $("#catimage").css({'overflow':'hidden'});
  
  $("#popup_container").css({'height':'325px'});
  if     ( id == "workshops"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'right',marginTop:'0px'});
  }
  else if( id == "impact"){
 		 $("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-324px'});
  }
  else if( id == "exhibitions"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-650px',marginLeft:'-165px'});
  }
  else if( id == "design-and-build"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-975px'});
  }
  else if( id == "flagship"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'right',marginTop:'-1300px'});
  }
  else if( id == "involve"){
  		$("#popup_container").css({'height':'345px'});
  		$("#catimage").css({'height':'345px'});
  		$("#catimage img").css({'float':'right',marginTop:'-1625px',marginRight:'-212px'});
  }
  else if( id == "coding"){
  		$("#popup_container").css({'height':'345px'});
  		$("#catimage").css({'height':'345px'});
  		$("#catimage img").css({'float':'right',marginTop:'-1970px',marginRight:'-196px'});
  }
  else if( id == "spotlights"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-2315px'});
  }
  else if( id == "quizzes"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-2640px'});
  }
  else if( id == "aerofest"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'right',marginTop:'-3290px',marginRight:'-196px'});
  }
  else if( id == "online"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'right',marginTop:'-2965px',marginRight:'-215px'});
  }
  else if( id == "soe"){
  		$("#popup_container").css({'height':'325px'});
  		$("#catimage").css({'height':'325px'});
  		$("#catimage img").css({'float':'left',marginTop:'-3615px',marginLeft:'-214px'});
  		$("#catimage").append("<img src=\"http://www.shaastra.org/2011/media/main/img/cat/soe.png\" style=\"position:absolute; bottom:0px;\"/>");
  }
  
  
  
}


function preloadimages(arr){
	var newimages=[]
	var arr=(typeof arr!="object")? [arr] : arr //force arr parameter to always be an array
	for (var i=0; i<arr.length; i++){
		newimages[i]=new Image()
		newimages[i].src=arr[i]
	}
	$("#right_arrow").fadeIn();
}

function loading(){
preloadimages(['http://www.shaastra.org/2011/media/main/img/aerofest.jpg','http://www.shaastra.org/2011/media/main/img/aerofest_copy.png','http://www.shaastra.org/2011/media/main/img/coding.jpg','http://www.shaastra.org/2011/media/main/img/coding_copy.png','http://www.shaastra.org/2011/media/main/img/design-and-build.jpg','http://www.shaastra.org/2011/media/main/img/design-and-build_copy.png','http://www.shaastra.org/2011/media/main/img/exhibitions.jpg','http://www.shaastra.org/2011/media/main/img/exhibitions_copy.png','http://www.shaastra.org/2011/media/main/img/flagship.jpg','http://www.shaastra.org/2011/media/main/img/flagship_copy.png','http://www.shaastra.org/2011/media/main/img/impact.jpg','http://www.shaastra.org/2011/media/main/img/impact_copy.png','http://www.shaastra.org/2011/media/main/img/involve.jpg','http://www.shaastra.org/2011/media/main/img/involve_copy.png','http://www.shaastra.org/2011/media/main/img/online.jpg','http://www.shaastra.org/2011/media/main/img/online_copy.png','http://www.shaastra.org/2011/media/main/img/quizzes.jpg','http://www.shaastra.org/2011/media/main/img/quizzes_copy.png','http://www.shaastra.org/2011/media/main/img/soe.jpg','http://www.shaastra.org/2011/media/main/img/soe_copy.png','http://www.shaastra.org/2011/media/main/img/spotlights.jpg','http://www.shaastra.org/2011/media/main/img/spotlights_copy.png' ,'http://www.shaastra.org/2011/media/main/img/workshops.jpg','http://www.shaastra.org/2011/media/main/img/workshops_copy.png']);
}
function load_popup1(){
  $("#footer_container").css({"position":"absolute","top":"593px"});
  $("body").css({"overflow":"hidden"});
  $("#container1").animate({"left":"-1200px"},600);
  $("#hospi").show().animate({"left":"125px"},600);
//   $("#content").hide();
  $("#right_arrow").fadeOut();
  $("#left_arrow").fadeIn();
  $("#container1").fadeOut();
  setTimeout(function(){$("body").css({"overflow":"auto"});},600);
}

function close_popup1(){
  closePopUp();
    $("#footer_container").css({"position":"relative","top":"0px"});
  $("body").css({"overflow":"hidden"});
  $("#container1").show().animate({"left":"0px"},600);
  $("#hospi").animate({"left":"1200px"},600).fadeOut();
  $("#right_arrow").fadeIn();
  $("#left_arrow").fadeOut();
  setTimeout(function(){$("body").css({"overflow":"auto"});},1000);
}
/*****
$(document).ready(function(){
	$("#popup_container").mouseleave(function(){
		closePopUp();
	});
});******/
