var randomTime = 15000;
var maxPercents = 300;
var minPercents = 70;
var runTime = 0.8;
var shitPassCounter = 0;
var z = 0;
var r = 0;
var f = 0;
var windowSize;
var windowHeight;
var animationTime = 300;
var animationFlowTime = 700;
var transitionTime = 750;
var actualColor;
var activeId;
var activeParentColor;
var contactTimeIn = 800;
var contactTimeOut = 500;
var today = new Date();
var fotoInfoTime = 400;
var aboutDownPosition;
var aboutUpPosition;
var footerTimeIn =  1000
var footerTimeOut = 500
var footerChangetime = 300;
var expiry = new Date(today.getTime() + 5 * 60 * 60 * 1000);
var smalerR = 0;
var smalerF = 0;
var smalerZ = 0;
var footerHover = false;
var footerIsOnFirst = true;
var footerTimeout = 4000;
var footerSpeedFirst = 1000;
var anchor;
var newsletterClick = false;
var newsletterblink = true;
var newsletternohide = true;
var newsletterShow = 5000;
var activeLookUpId = -1; 
var additionalOpened = 'cc';

//var decoder=['fashion','photo','graphics','fashion/t-shirt','fashion/shoes','fashion/accesories','fashion/other','fashion/other_fashion','fashion/people_and_fashion','photo/people','photo/nature','photo/animals','photo/macro','photo/city','photo/other','photo/urban_exploration','photo/analog','graphics/graphic_design','graphics/poster','graphics/draw/paint','graphics/other','graphics/logos/CI','graphics/illustration'];
//var coder=['r','z','f','r-1','r-2','r-3','r-4','r-5','r-6','z-1','z-2','z-3','z-4','z-5','z-6','z-7','z-8','f-1','f-2','f-3','f-4','f-5','f-6'];
var newsletterName=['módě','fotkách','designu','fashion','photos','design'];
var newsletterVal = [true,true,true];
//var anchorTable = [decoder, coder];
//var first = true;

//var buttonR = jQuery("#button-r");


var buttonZ;
var buttonR;
var buttonF;
var subButtonsR;
var subButtonsZ;
var subButtonsF;
var contact;
var contactLines;
var footer;
var subButtonsR1;
var subButtonsR2;
var subButtonsR3;
var subButtonsR4;
var subButtonsR5;
var subButtonsR6;
var subButtonsF1;
var subButtonsF2;
var subButtonsF3;
var subButtonsF4;
var subButtonsF5;
var subButtonsZ1;
var subButtonsZ2;
var subButtonsZ3;
var subButtonsZ4;
var subButtonsZ5;
var subButtonsZ6;


 /*
$.ajaxSetup({
    'beforeSend' : function(xhr) {
        xhr.overrideMimeType('text/html; charset=cp1250');
    }
});   */
                      
$(document).ready(function(){

  buttonZ = $("#button-z");
  buttonR = $("#button-r");
  buttonF = $("#button-f");
  subButtonsR = $(".sub-buttons-r");
  subButtonsZ = $(".sub-buttons-z");  
  subButtonsF = $(".sub-buttons-f");
  footer = $("#footer");
  contact = $("#contact");
  contactLines =  $("#contactLines");
  
  subButtonsR1 = $('#sub-buttons-r-1');
  subButtonsR2 = $("#sub-buttons-r-5"); 
  subButtonsR3 = $("#sub-buttons-r-2");
  subButtonsR4 = $("#sub-buttons-r-3");
  subButtonsR5 = $("#sub-buttons-r-4");
  subButtonsR6 = $("#sub-buttons-r-6");
  subButtonsF1 = $("#sub-buttons-f-1");
  subButtonsF2 = $("#sub-buttons-f-2");
  subButtonsF3 = $("#sub-buttons-f-3");
  subButtonsF4 = $("#sub-buttons-f-4");
  subButtonsF5 = $("#sub-buttons-f-5");
  subButtonsF6 = $("#sub-buttons-f-6");
  subButtonsZ1 = $("#sub-buttons-z-1");
  subButtonsZ2 = $("#sub-buttons-z-2");
  subButtonsZ3 = $("#sub-buttons-z-3");
  subButtonsZ4 = $("#sub-buttons-z-4");
  subButtonsZ5 = $("#sub-buttons-z-5");
  subButtonsZ6 = $("#sub-buttons-z-6");
  subButtonsZ7 = $("#sub-buttons-z-7");
  subButtonsZ8 = $("#sub-buttons-z-8");
  $('#authors').css("opacity","0.0");
             
//   subButtonsZ.css("left",windowSize);
  // subButtonsF
   //jessica(); 
   
   
   
   windowSize = GetWidth()/2-350;
   windowHeight  = GetHeight ();
   aboutDownPosition = windowHeight-29;
   aboutUpPosition = windowHeight - 464;
   aboutDownPosition = windowHeight-23
   footer.css("top",aboutDownPosition);
   footer.stop().animate({top : ""+(aboutUpPosition)+"px"},{queue:false,duration:footerTimeIn});
 	 setFooter();
   footer.css("display","block");
   footer.click(function(){
    footerHover = false;
    hideFooter();
    });
 
   buttonZ.css("left",windowSize);
   buttonF.css("left",windowSize);
   buttonR.css("left",windowSize);
   subButtonsR.css("left",windowSize);
   subButtonsZ.css("left",windowSize);
   subButtonsF.css("left",windowSize);
   $("#contact").css("left",GetWidth()/2+350);
   $("#contactLines").css("left",GetWidth()/2+350);
   subButtonsR.click(function () { 
          subButtonsR.dequeue();
          $(this).subButtonClick("r");       
    });
    subButtonsZ.click(function () { 
          subButtonsZ.dequeue();
          $(this).subButtonClick("z");       
    });
    subButtonsF.click(function () { 
          subButtonsF.dequeue();
          $(this).subButtonClick("f");       
    });
   
    buttonZ.click(function () { 
               buttonClick("z");
    });
    buttonF.click(function () { 
               buttonClick("f");
    });
    buttonR.click(function () { 
               buttonClick("r");
    });
    
    $("#newsletterButton").click(function(){
      transitionByAddr("news.php");
    });
    
    $('#contactLines').hover(function()     
    {
			$("#contact").stop().animate({top:'0px'},{queue:false,duration:contactTimeIn});
		}, function() {
			$("#contact").stop().animate({top:'-70px'},{queue:false,duration:contactTimeOut});
		});
		
		$('#contact').hover(function()     
    {
			$("#contact").stop().animate({top:'0px'},{queue:false,duration:contactTimeIn});
		}, function() {
			$("#contact").stop().animate({top:'-70px'},{queue:false,duration:contactTimeOut});
		});
		

		$('#newsletterInput').hover(function()     
    {
			$("#newsletter").stop().animate({left:'0px'},{queue:false,duration:contactTimeIn});
			$('.newsletterHeader').delay(contactTimeIn).animate({top : '-66px',opacity: '1.0'},contactTimeIn);
			if (!newsletterClick){
        $('#newsletterr').delay(contactTimeIn+200).animate({top : '-1px'},contactTimeIn);
  			$('#newsletterz').delay(contactTimeIn+400).animate({top : '-1px'},contactTimeIn);
  			$('#newsletterf').delay(contactTimeIn+600).animate({top : '-1px'},contactTimeIn);
  		}		
  		$("#newsletterSubmit").stop().clearQueue().css("opacity","0");
  		newsletterblink = false;
  		
		  
		}, function() {
		  if (!newsletternohide){
  			$("#newsletter").stop().animate({left:'-163px'},{queue:false,duration:contactTimeOut});
  			$('.newsletterHeader').clearQueue().animate({top : '-50px',opacity: '1.0'},contactTimeOut);
  			if (!newsletterClick){
          $('#newsletterr').clearQueue().animate({top: '-20px'},contactTimeOut);
    			$('#newsletterz').clearQueue().animate({top: '-20px'},contactTimeOut);
    			$('#newsletterf').clearQueue().animate({top: '-20px'},contactTimeOut);
    		}
    	}
    	newsletternohide = false;
  		//newsletterblink = true;
		});
		
		
		$('#newsletter').hover(function()     
    {
			$("#newsletter").stop().animate({left:'0px'},{queue:false,duration:contactTimeIn});
			$('.newsletterHeader').delay(contactTimeIn).animate({top : '-66px',opacity: '1.0'},contactTimeIn);
			if (!newsletterClick){
        $('#newsletterr').delay(contactTimeIn+200).animate({top : '-1px'},contactTimeIn);
  			$('#newsletterz').delay(contactTimeIn+400).animate({top : '-1px'},contactTimeIn);
  			$('#newsletterf').delay(contactTimeIn+600).animate({top : '-1px'},contactTimeIn);
  		}		
  		$("#newsletterSubmit").stop().clearQueue().css("opacity","0");
  		newsletterblink = false;
  		
		  
		}, function() {
		  if (!newsletternohide){
  			$("#newsletter").stop().animate({left:'-163px'},{queue:false,duration:contactTimeOut});
  			$('.newsletterHeader').clearQueue().animate({top : '-50px',opacity: '1.0'},contactTimeOut);
  			if (!newsletterClick){
          $('#newsletterr').clearQueue().animate({top: '-20px'},contactTimeOut);
    			$('#newsletterz').clearQueue().animate({top: '-20px'},contactTimeOut);
    			$('#newsletterf').clearQueue().animate({top: '-20px'},contactTimeOut);
    		}
    	}
    	newsletternohide = false;
  		//newsletterblink = true;
		});
		    
		$('.newsletterButtons').toggle(function(){
		  newsletterClick = true;
      $(this).animate({top: '-14px'},contactTimeOut);
      var newsid = $(this).attr("id");
      newsid = newsid.substring(10); 
      var newsIndex;
      switch(newsid){
        case "r": newsIndex = 0; break;
        case "z": newsIndex = 1; break;
        case "f": newsIndex = 2; break; 
      }
      newsletterVal[newsIndex] = false;
      changeNewsleterInfoBox(newsIndex);  
      
    }, function() {
      $(this).animate({top: '-1px'},contactTimeOut);
      var newsid = $(this).attr("id");
      newsid = newsid.substring(10); 
      var newsIndex;
      switch(newsid){
        case "r": newsIndex = 0; break;
        case "z": newsIndex = 1; break;
        case "f": newsIndex = 2; break; 
      }
      newsletterVal[newsIndex] = true;
      changeNewsleterInfoBox(newsIndex); 
    });
    
    $('.newsletterButtons').hover(function(){
      var newsid = $(this).attr("id");
      newsid = newsid.substring(10); 
      $("#newsletterInfobox").css("opacity","1");
      $("#newsletterInfobox").clearQueue().animate({left: $(this).offset().left},contactTimeOut);
      var newsIndex;
      switch(newsid){
        case "r": newsIndex = 0; break;
        case "z": newsIndex = 1; break;
        case "f": newsIndex = 2; break; 
      }
      changeNewsleterInfoBox(newsIndex); 
    
       
    }, function() {
      $("#newsletterInfobox").css("opacity","0");
    });
    
    $('#newsletterSubmit').hover(function(){
      $(this).css("opacity","1");
    }, function() {
      $(this).clearQueue().css("opacity","0");
    });
    
    $("#newsletterSubmit").click(function(){
      var newsletterReg = "newsletterRegister.php?";
      newsletterReg += "email="+$("#newsletterInput").val();
      newsletterReg += "&fashion=";
      newsletterReg += (newsletterVal[0]) ? 1:0;
      newsletterReg += "&foto=";
      newsletterReg += (newsletterVal[1]) ? 1:0;
      newsletterReg += "&graphics=";
      newsletterReg += (newsletterVal[2]) ? 1:0;
      //alert (newsletterReg);
      $("#newsletterResult").load(newsletterReg);
      
    });
    
		
    		
    if (GetCookie("user")=="magi")
      transitionByAddr(GetCookie("loadThis"));
    $(".editFotos").click(function () {
      var editID = $(this).attr("id");
      $("#content").load("editFotos.php?id="+editID);
      SetCookie('loadThis', "editFotos.php?id="+editID, expiry);
      return false;
    });
    
  $("#home").click(function(){transitionByAddr("blog.php")});
  $("#home").tipsy({gravity: 'w', fade: true});  
  $("#lang").tipsy({gravity: 'w', fade: true}); 
    
  randomAnimations("r");
  randomAnimations("z");
  randomAnimations("f");
  //setTimeout("randomNewsletterBlink();",30000);
  randomNewsletterBlink();
  //setTimeout("showNewsletter();",newsletterShow);
  
  var query = location.href.split('#');
  anchor = query[1];
  
  if (!loadAnchoredContent())
     loadBlog();
 // parent.location.hash = "hello";

});

function showNewsletter(){
  $("#newsletterContent").mouseenter();
  newsletterNoHide = true;
}

function randomNewsletterBlink(){
  if (newsletterblink){
    var blink = 300;
    var count = 0;
    for(var i= 0;i<10; i++){
      $('#newsletterSubmit').delay(blink).animate({opacity: 1},0);
      $('#newsletterSubmit').delay(blink).animate({opacity: 0},0);
    }
  };

  setTimeout("randomNewsletterBlink();",Math.random() * 20000 + 20000);
  
}

function changeNewsleterInfoBox (id){
  var newsletterOpened;
  if (lang=="en"){
    if (newsletterVal[id]) newsletterOpened = "<b>yes</b>"; else newsletterOpened = "<b>no</b>";                                              
    $("#newsletterInfobox").html("receive news about "+newsletterName[id+3] + ": " + newsletterOpened );
    }
  else{
    if (newsletterVal[id]) newsletterOpened = "<b>ano</b>"; else newsletterOpened = "<b>ne</b>";                                              
    $("#newsletterInfobox").html("Přijímat novinky o "+newsletterName[id] + ": " + newsletterOpened );
    }
  }  


function changeAnchor(anchorId){
  for(i=0;i<lookUpTable[0].length;i++){
    if (lookUpTable[1][i] == anchorId){
        parent.location.hash = lookUpTable[0][i];
      break;
    }
  }  
}

function zClick(){
  alert("yeah");
}

$.fn.subButtonClick = function(color) 
{   
    var thisId = $(this).attr("id");
      
    if(thisId!=activeId){
     if(thisId != additionalOpened )
      {

        $(this).animate({ 
          width: "+=26px",
          height: "17px"
        }, animationTime);
        $(this).dequeue();    
        $(this).animate({ 
          paddingTop : "2px"
        }, animationTime/2);  
      }
      //else
      //{alert (additionalOpened);}
      
      if(thisId.length == activeId.length)
      {
       //alert("==");
       $("#"+activeId).animate({  
        width: "-=26px", 
        height: "16px",
        paddingTop : "0px"
        }, animationTime );
        
        if (thisId.length == 15)
          additionalOpened = "addX";   
                
      }
      else
      {
        if(thisId.length == 15 && activeId.length == 17 ) // its level 2  from level 1
        {
          //alert("2");
          $("#"+activeId).animate({  
            width: "-=26px", 
            height: "16px",
            paddingTop : "0px"
          }, animationTime );
        }
        
        if (thisId != additionalOpened && thisId.length != 17)
          {
            //alert("3");
            $("#"+additionalOpened).animate({  
              width: "-=26px", 
              height: "16px",
              paddingTop : "0px"
            }, animationTime );
            additionalOpened = "addX"; 
          } 
      } 
      
      if (lookUpTable[3][getActiveLookUpTableId(thisId.substring(12))]>0)
        additionalOpened = thisId; //alert("seted")  }     
      
      var actualIdParent = activeId; //possible parent
      activeId = $(this).attr("id");
      var actualId = activeId.substring(12);
     // alert(actualIdParent.substring(12));
     // alert(actualId.substring(0,3));
      if (actualIdParent.length!=actualId.length)
        if (actualIdParent.substring(12,15)!=actualId.substring(0,3))
          treeHide(getActiveLookUpTableId(actualIdParent.substring(12,15)),0);
      setActiveLookUpTableId(actualId);
      if (lookUpTable[3][activeLookUpId] != 0)
      {
        var i;
        for (i=1;i<=lookUpTable[3][activeLookUpId];i++)
        {
          $("#sub-buttons-"+lookUpTable[1][activeLookUpId]+"-"+i).show(1000);  
        }
      }
       
      transition(actualId);
      changeAnchor(actualId);
      
    }
}

function treeHide(lookUpID,timer){
  var i;
  var count = lookUpTable[3][lookUpID];
  for (i=lookUpTable[3][lookUpID];i>=1;i--){
    var tryId = getActiveLookUpTableId(lookUpTable[1][lookUpID]+"-"+i)
    if (lookUpTable[3][tryId]>0){
      timer += treeHide(tryId,timer);  
    }
    setTimeout("$('#sub-buttons-"+lookUpTable[1][lookUpID]+"-"+i+"').hideButton('"+lookUpTable[1][lookUpID]+"');", timer*100);
    
    timer ++;
  }
  return timer;
}

function hideLast(lookUpID,level){
  var i;
  var count = lookUpTable[3][lookUpID];
  for (i=lookUpTable[3][lookUpID];i>=1;i--){
    var tryId = getActiveLookUpTableId(lookUpTable[1][lookUpID]+"-"+i)
  //  alert(tryId);
   // alert(lookUpTable[1][tryId]);
    //alert(lookUpTable[3][tryId]);
    if (lookUpTable[3][tryId]>0){
      
      if (level==0)
        treeHide(tryId,0);
      else
        hideLast(tryId,level+1);  
    }
    
  }
}

function buttonClick(color) {
   if (activeParentColor!=color){   
      $(".lines").dequeue();
      $(".button").dequeue();
      
      $("#button-"+activeParentColor).animate({ 
        width: "-=24px",
        height: "16px",
        fontSize: "0.75em"
      }, animationTime );
      $("#button-"+color).dequeue();
      $("#button-"+color).animate({ 
        width: "+=24px",
        height: "19px",
        fontSize: "1.01em"
      }, animationTime);

        setTimeout("hideCount('"+color+"');",1500);
        
      }
      var lookUpId = getActiveLookUpTableId(color);
      hideLast(lookUpId,0);
      changeAnchor(color);    
      activeParentColor = color;
      
      transition(color);
      actualId = color;
      
      footerTransition(color);
      
     activeToSmall();       
      
     if (color!='r'){
       treeHide(getActiveLookUpTableId('r'),0);
       //alert("after");
      /* setTimeout("subButtonsR1.hideButton('r-1');",600);
       setTimeout("subButtonsR2.hideButton('r-5');",500);
       setTimeout("subButtonsR3.hideButton('r-2');",400);
       setTimeout("subButtonsR4.hideButton('r-3');",300);
       setTimeout("subButtonsR5.hideButton('r-4');",200);
       setTimeout("subButtonsR6.hideButton('r-6');",100); */
     }
     
     if (color!='z'){
       treeHide(getActiveLookUpTableId('z'),0);
     /*  setTimeout("subButtonsZ1.hideButton('z-1');",700);
       setTimeout("subButtonsZ2.hideButton('z-2');",600);
       setTimeout("subButtonsZ3.hideButton('z-3');",500);
       setTimeout("subButtonsZ4.hideButton('z-4');",400);
       setTimeout("subButtonsZ5.hideButton('z-5');",400);
       setTimeout("subButtonsZ7.hideButton('z-7');",300);
       setTimeout("subButtonsZ8.hideButton('z-8');",200);
       setTimeout("subButtonsZ6.hideButton('z-6');",100);   */
     }
     
     if (color!='f'){
       treeHide(getActiveLookUpTableId('f'),0);
       /*setTimeout("subButtonsF1.hideButton('f-1');",600);
       setTimeout("subButtonsF5.hideButton('f-5');",500);
       setTimeout("subButtonsF2.hideButton('f-2');",400);
       setTimeout("subButtonsF6.hideButton('f-6');",300);
       setTimeout("subButtonsF3.hideButton('f-3');",200);
       setTimeout("subButtonsF4.hideButton('f-4');",100);*/
     }
     
     $(".sub-buttons-"+color).dequeue();
     setTimeout("$('#sub-buttons-"+color+"-1').show(animationFlowTime);",Math.random() * 1000);
     setTimeout("$('#sub-buttons-"+color+"-2').show(animationFlowTime);",Math.random() * 1000); 
     setTimeout("$('#sub-buttons-"+color+"-3').show(animationFlowTime);",Math.random() * 1000);
     setTimeout("$('#sub-buttons-"+color+"-4').show(animationFlowTime);",Math.random() * 1000);
     setTimeout("$('#sub-buttons-"+color+"-5').show(animationFlowTime);",Math.random() * 1000); 
     setTimeout("$('#sub-buttons-"+color+"-6').show(animationFlowTime);",Math.random() * 1000);
     setTimeout("$('#sub-buttons-"+color+"-7').show(animationFlowTime);",Math.random() * 1000); 
     setTimeout("$('#sub-buttons-"+color+"-8').show(animationFlowTime);",Math.random() * 1000);     
     actualColor = color;

     
}

function hideCount(color){
//alert(color);
    if (color=='r' && smalerR == 1) return;
    if (color=='z' && smalerZ == 1) return;
    if (color=='f' && smalerF == 1) return;
    var divWidth = $("#button-"+color).width();
    var countWidth = $("#buttonCount-"+color).width()-4;
    $("#buttonCount-"+color).animate({ 
       opacity: "0.0",
       width : "0px"
     }, 1000);
/*    var countWidth = $("#buttonCount-"+color).width();
    alert (countWidth+" "+countWidth );
     $("#buttonCount-"+color).animate({ 
       opacity: "0.0"
     }, 1000);   */
      $("#button-"+color).delay(1000).animate({ 
       width: "-="+countWidth+"px"
     }, 1000);                  
     if (color=='r') smalerR = 1; 
     if (color=='z') smalerZ = 1; 
     if (color=='f') smalerF = 1; 
}

$.fn.hideButton = function(id) 
{
  $(this).dequeue();
/*  $(this).animate({ 
       opacity: "0.0",
       height : "1px"
     }, animationFlowTime); */
  //$(this).slideUp(animationFlowTime);
  $(this).hide(animationFlowTime);   
  
}
$.fn.setDefaultSubButton = function() 
{ 
  $(this).css("height","14px");   
  $(this).css("paddingTop","0px"); 
  $(this).css("padding-top","0px");                               
  $(this).css("width","66px");
 
}

function footerTransition(color){
  if (footerIsOnFirst == true){
    setTimeout("footerTransition('"+color+"')",500);
  }
  else{
    $(".footerContent").css("display","none");
    footer.animate({top : "+=29px"},footerChangetime).delay(footerChangetime).animate({top : ""+aboutDownPosition+"px"},footerChangetime);
    setTimeout("$('#footer').css('background-image',\"url('grafika/cedulky-"+color+"-nove.png')\")",footerChangetime);
    setTimeout("footerDisplayDivs('"+color+"');", 3 * footerChangetime);
  }
}

function footerDisplayDivs(color){
  if (color=="r"){
    $("#footerContentFashion").css("display","block");
    $("#footerContentPhoto").css("display","none");
    $("#footerContentGraphics").css("display","none");
  }
  if (color=="z"){
    $("#footerContentFashion").css("display","none");
    $("#footerContentPhoto").css("display","block");
    $("#footerContentGraphics").css("display","none");
  }
  if (color=="f"){
    $("#footerContentFashion").css("display","none");
    $("#footerContentPhoto").css("display","none");
    $("#footerContentGraphics").css("display","block");
  }
}

function setFooter(){

    setTimeout("hideFooter()",footerTimeout);
    $('#footer').hover(function()     
    { 
      footerHover = true;
			footer.stop().animate({top : ""+(aboutUpPosition)+"px"},{queue:false,duration:footerTimeIn});
			$('#authors').delay(footerTimeIn).animate({top : '0px',opacity: '1.0'},footerTimeOut)
			$("#contact").delay(footerTimeIn).animate({top:'0px'},contactTimeIn);
			
		}, function() {
			footer.stop().animate({top : ""+(aboutDownPosition)+"px"},{queue:false,duration:footerTimeOut});
		  $('#authors').clearQueue().delay(footerTimeOut).animate({top : '15px',opacity: '0.0'},footerTimeOut);
      $("#contact").clearQueue().delay(3000).animate({top:'-70px'},contactTimeOut);
      footerHover = false;
      footerIsOnFirst = false;
    });
		
		//setTimeout("$('#footer').animate({opacity:'0.02'},3000);",7000);

}

function hideFooter(){
  setTimeout("footerIsOnFirst = false",footerSpeedFirst);
  //setTimeout("showNewsletter();",1000);
//  showNewsletter();
  if (footerHover == false)
    footer.animate({top : ''+(aboutDownPosition)+'px'},footerSpeedFirst);  
}

function setOpacity(color,opacity){
/*$(".sub-buttons-"+color).dequeue();
$(".sub-buttons-"+color).animate({ 
  opacity : ""+opacity
}, animationTime);              */
$("#button-"+color).dequeue();
$("#button-"+color).animate({ 
  opacity : ""+opacity
}, animationTime*5);
$("#menu-"+color).animate({ 
  opacity : ""+opacity
}, animationTime*5); 

}

function activeToSmall(){
  $($("#"+activeId)).dequeue();
  $($("#"+activeId)).animate({  
        width: "-=26px",
        height: "16px",
        paddingTop : "0px"
      }, animationTime );    
  activeId = "X";
    
  $("#"+additionalOpened).dequeue();
  $("#"+additionalOpened).animate({  
              width: "-=26px", 
              height: "16px",
              paddingTop : "0px"
            }, animationTime );
            additionalOpened = "addX";
            
  
  //additionalOpened = "X";
    
}

function transition(newId){ 
  setActiveLookUpTableId(newId); 
  SetCookie('loadThis', "gallery.php?id="+newId, expiry); 
  $('#content').fadeOut(transitionTime, function() {
   // if (newId=='r' && smalerR == 1) return;
   // if (newId=='z' && smalerZ == 1) return;
   // if (newId=='f' && smalerF == 1) return;
    $("#content").load("gallery.php?id="+lookUpTable[2][activeLookUpId], function() {
      $("#content").css("display","none");
      $('#content').fadeIn(transitionTime);
    });
  });
  
}

function transitionByAddr(addr){
  $('#content').fadeOut(transitionTime, function() {
    $("#content").load(addr, function() {
      $("#content").css("display","none");
      $('#content').fadeIn(transitionTime);
    });
  });
}



function randomAnimations(lineColor) {   
   var zIn = (Math.random()-0.5)*maxPercents;
   if (zIn>0)
      zIn += minPercents;
   else
      zIn -= minPercents;
   z = zIn;
   var zTime = (Math.random()+runTime) * randomTime;
   $("#menu-"+lineColor).animate({backgroundPosition: ''+z+'px 0px'},zTime);
   $("#button-"+lineColor).animate({left: ''+(z+windowSize)+'px'},zTime);
   $(".sub-buttons-"+lineColor).animate({left: ''+(z+windowSize)+'px'},zTime);
   
   setTimeout("randomAnimations('"+lineColor+"');",zTime+1000);
}

function randomTimeThis(){
    alert (Math.random() * 500);
    return (Math.random() * 500);
}

function setActiveLookUpTableId(magiID)      //this is not setter as known from java.
{
  for(i=0;i<lookUpTable[0].length;i++){
    if (lookUpTable[1][i] == magiID){
      activeLookUpId = i;
      break;  
    }
  }  
}

function getActiveLookUpTableId(magiID)
{
  for(i=0;i<lookUpTable[0].length;i++){
    if (lookUpTable[1][i] == magiID){
      return i;  
    }
  }  
}

function loadBlog(){ transitionByAddr("blog.php"); }


function loadAnchoredContent(){
  for(i=0;i<lookUpTable[0].length;i++){
    if (lookUpTable[0][i] == anchor){
      anchorFound(lookUpTable[1][i] );
      return true;
    }
  }
  return false;
}

function anchorFound(id){
  var color = id.substring(0,1);
  buttonClick(color);
  if (id.length>1)
    setTimeout("$('#sub-buttons-"+id+"').subButtonClick("+color+");",500);
    //$("#sub-buttons-"+id).subButtonClick(color);
  //alert("$('#sub-buttons-"+id+"').subButtonClick("+color+");");
  transition(id);
   
}

function GetWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}

function GetHeight()
{
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  }
            
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal (j);
      }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
    }
  return null;
  }
  
  function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) { endstr = document.cookie.length; }
  return unescape(document.cookie.substring(offset, endstr));
  }
  
  
  function getElementHeight(Elem) {
  if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}


/*  switch(anchor)
  {
  case 'fashion/t-shirt':
    anchorFound('r-1');
  break;
  case 'fashion/shoes':
    anchorFound('r-2');
  break;
  case 'fashion/accesories':
    anchorFound('r-3');
  break;
  case 'fashion/other':
    anchorFound('r-4');
  break;
  case 'fashion/other_fashion':
    anchorFound('r-5');
  break;
  case 'fashion/people_and_fashion':
    anchorFound('r-6');
  break;
  
  case 'photo/people':
    anchorFound('z-1');
  break;
  case 'photo/nature':
    anchorFound('z-2');
  break;
  case 'photo/animals':
    anchorFound('z-3');
  break;
  case 'photo/macro':
    anchorFound('z-4');
  break;
  case 'photo/city':
    anchorFound('z-5');
  break;
  case 'photo/other':
    anchorFound('z-6');
  break;
  
  
  case 'graphics/graphic_design':
    anchorFound('f-1');
  break;
  case 'graphics/poster':
    anchorFound('f-2');
  break;
  case 'graphics/draw/paint':
    anchorFound('f-3');
  break;
  case 'graphics/other':
    anchorFound('f-4');
  break;
  
  case 'fashion':
    anchorFound('r');
  break;
  case 'photo':
    anchorFound('z');
  break;
  case 'graphics':
    anchorFound('f');
  break;
  }   */
