  // Game-access JS


  // INICIALIZATION ////////////////////////////////////////////////
  
  
  var activeSection = 0;
  var activeSite = 0;
  var oldActiveSection = 0;
  var oldActiveSite = 0;
  var $j = jQuery.noConflict();
	var $ = {};
	var next_car = 2;
	var running_car;
	var specialParameter;
  
  // COLORS /////////////////////////////////////////////////////////
  menuColor1 = "#ed0a0a";
  menuColor2 = "#ade405";
  menuColor3 = "#e40598";
  menuColor4 = "#05b2e4";
  menuColor5 = "#f3d902";
  menuColor6 = "#eb8414";
  menuColor7 = "#05e48d";
  
  // HASH //////////////////////////////////////////////////////////
  hash = "qa97621ca56as5dasd546aszx213a";
 
  
  /*
  ******  ON LOAD READY
  */
	$j(document).ready(function(){
		 
    
    $j.history.init(pageload);  //init


    //winWidth = window.innerWidth;
    
    //138
    //alert(winWidth);
    //loginRight = (winWidth-1004)/2; 
    //alert("ads");
       
      //$j('#login').css("right",50); 
		
		///////////////////////////////////
		$j(".fws").mouseover(function()   {         $j('.fws1 a').fadeIn(200);           });
    $j(".fws1 a").mouseout(function() {         $j('.fws1 a').fadeOut(200);          }); 
    
    $j(".game-access").mouseover(function() {   $j('.game-access1 a').fadeIn(200);   });
    $j(".game-access1 a").mouseout(function() { $j('.game-access1 a').fadeOut(200);  });
	  
	  $j('#face a').animate({ opacity: 0.01}, 20);
	  $j('#tweet a').animate({ opacity: 0.01}, 20);
	  $j('#dellic a').animate({ opacity: 0.01}, 20);
	  $j('#rss a').animate({ opacity: 0.01}, 20);
	
	  $j("#face a").mouseover(function() {  $j('#face a').animate({ opacity: 1.0}, 200) });
    $j("#face a").mouseout(function() { $j('#face a').animate({ opacity: 0.01}, 200) });
    
    $j("#tweet a").mouseover(function() {  $j('#tweet a').animate({ opacity: 1.0}, 200) });
    $j("#tweet a").mouseout(function() { $j('#tweet a').animate({ opacity: 0.01}, 200) });
    
    $j("#dellic a").mouseover(function() {  $j('#dellic a').animate({ opacity: 1.0}, 200) });
    $j("#dellic a").mouseout(function() { $j('#dellic a').animate({ opacity: 0.01}, 200) });
    
    $j("#rss a").mouseover(function() {  $j('#rss a').animate({ opacity: 1.0}, 200) });
    $j("#rss a").mouseout(function() { $j('#rss a').animate({ opacity: 0.01}, 200) });
	
	  
    ///////////////////////////////////
		
		// MENU-MOUSEOVER ///////////////////////////////////////////////////
    $j("a[id*='m0']").mouseover(function() {
      var idecko = $j(this).attr('id'); idecko = idecko[2];
      if(activeSection != idecko){ 
        hide_menu(); 
        $j('#l0'+idecko).show();
        $j('#menu-hide').show();   
        $j('#a0'+idecko).fadeIn(200);      
      }
    });
    
    // MENU-CLICK /////////////////////////////////////////////////////////
    $j("div[id*='l0']").click(function() {
      var idecko = $j(this).attr('id'); idecko = idecko[2];
      switch(idecko){
        case "1": newName = "/o-akci/"; break; 
        case "2": newName = "/navstevnik/"; break;
        case "3": newName = "/press/"; break;
        case "4": newName = "/konference/"; break;
        case "5": newName = "/komunita/"; break;
        case "6": newName = "/partneri/"; break;
        case "7": newName = "/kontakt/"; break;
        default:  newName = "/o-akci/";      
      }
      window.location.hash = "#"+newName;
      $j.history.load(newName);
    }); 
    
    $j("a[id*='m0']").click(function() {
      var idecko = $j(this).attr('id'); idecko = idecko[2];
      switch(idecko){
        case "1": newName = "/o-akci/"; break; 
        case "2": newName = "/navstevnik/"; break;
        case "3": newName = "/press/"; break;
        case "4": newName = "/konference/"; break;
        case "5": newName = "/komunita/"; break;
        case "6": newName = "/partneri/"; break;
        case "7": newName = "/kontakt/"; break;
        default:  newName = "/o-akci/";      
      }
      window.location.hash = "#"+newName;
      $j.history.load(newName);
    }); 

    $j('#menu-hide').mouseover(function() {    
      hide_menu();
      $j('#menu-hide').hide();
    });
      
    $j("#buttonlog").click(function() {
      //$j("#start").slideToggle("fast");
      $j("#logon").slideToggle("fast");
      $j("#social").slideToggle("fast");
       
    });  
      
    $j.scrollTo.defaults.axis = 'xy';
  	$j('#downmenu a').click(function(){
  	  //$j.scrollTo( "#body", {duration:600});
  	  
      var hasah = this.href;			
			hasah = hasah.replace(/^.*#/, '');
			
      $j.history.load(hasah);
      
			return false;               
  	});
               
		
	 
		$j("a[@rel='nav']").click(function(){
			
     /* var hasah = this.href;			
			hasah = hasah.replace(/^.*#/, '');
			
      $j.history.load(hasah);
			return false; */
		});
	
		
	});

 // PAGELOAD ///////////////////////////////
 function pageload(hasah) { 
			
			var address = hasah.split("/");
			var newSection;
			var newSite;
			
			
			switch(address[1]){
        case "o-akci":     newSection = 1; 
          switch(address[2]){
            case "zakladni-informace":  newSite = 1; break;
            case "faq":                 newSite = 2; break;
            case "novinky":             newSite = 3; break;
            //case "rozhovory":           newSite = 4; break;
            default:                    newSite = 1;      
          } break;  
        case "navstevnik": newSection = 2;
          switch(address[2]){
            case "proc-se-ucastnit":    newSite = 1; break;
            case "vstupenky":           newSite = 2; break;
            case "registrace":          newSite = 3; break;
            case "ubytovani-v-brne":  newSite = 4; break;
            case "doprava-mesto-a-restaurace":     newSite = 5; break;
            case "pravidla-akce":       newSite = 6; break;
            case "vip":          newSite = 7; break;
            
            default:                    newSite = 1;      
          } break;
        case "press":      newSection = 3; 
          switch(address[2]){
            case "informace-pro-novinare": newSite = 1; break;
            case "akreditace":             newSite = 2; break;
            case "presskit":               newSite = 3; break;

            default:                       newSite = 1;      
          } break;
        case "konference": newSection = 4;
          switch(address[2]){
            case "prednasejici":     newSite = 1; break;
            case "prednasky":        newSite = 3; break;
            case "program":          newSite = 3; break;
            //case "hotelovy-plan":    newSite = 4; break;
            case "souteze":          newSite = 5; break;
            default:                       newSite = 1;      
          } break;
        case "komunita":   newSection = 5; newSite = 1; break;
        case "partneri":   newSection = 6; newSite = 1; break;
        case "kontakt":    newSection = 7; newSite = 1; break;
        default:           newSection = 1; newSite = 1;  break;   
      }
      if(address[3]) specialParameter=address[3];
      
      
      //alert(newSection);
			//alert(newSite);
			
			
			setSite(newSection,newSite,0);
      			
	}

 // HIDEMENU ///////////////////////////////
 function hide_menu() {    
    if(activeSection != 1) { $j('#a01').fadeOut(80); $j('#l01').hide();  };
    if(activeSection != 2) { $j('#a02').fadeOut(80); $j('#l02').hide();  };
    if(activeSection != 3) { $j('#a03').fadeOut(80); $j('#l03').hide();  };
    if(activeSection != 4) { $j('#a04').fadeOut(80); $j('#l04').hide();  };
    if(activeSection != 5) { $j('#a05').fadeOut(80); $j('#l05').hide();  };
    if(activeSection != 6) { $j('#a06').fadeOut(80); $j('#l06').hide();  }; 
    if(activeSection != 7) { $j('#a07').fadeOut(80); $j('#l07').hide();  };
    if(oldActiveSection > 0) { $j('#m0'+oldActiveSection).animate({ color: '#A5A5A5' }, 300 ); };       
  };

  // SET SITE ///////////////////////////////
  function setSite(theme,site,mode) {    
    
    if(theme != activeSection) { setTheme(theme,site); return; }
    $j.scrollTo( "#body", {duration:450});
     
    
    if(mode == 1 || activeSite != site){
      additional =  "";
      oldActiveSite = activeSite;
      activeSite = site;     
      var adresa = "ajax/getGraphic.php?hash="+hash+"&menu="+theme+"&site="+site;       
      $j.post(adresa,{}, function(data) {$j('#graphic #reload-g').html(data); $j('#graphic-bg').fadeIn(1000); $j('#graphic .title').fadeIn(500);  });
      
      if(theme==3 && site==2) {theme=2; site=3; additional="?vers=2"; }
      if(theme==2 && site==7) {theme=2; site=3; additional="?vip=1&code="+specialParameter; }
      
      adresa = "pages/getPage"+theme+"-"+site+".php"+additional;       
      $j.post(adresa,{}, function(data) {
        $j('#content').html(data); 
        if(theme==4 && site==3){} else { $j("#content .main-box .title").css({ color: actualColor }); }  
        $j('#content a').each(function (){
        
          if(theme==4 && site==3){} else { $j(this).css({ color: actualColor });    }  
          
        });
        
       
         
        $j('#content a').underline({
          color: actualColor, // underline color (default black)
          width: 1,         // underline thickness (default 1)
          duration: 250     // animation speed (default 500)
        });
        
        $j('#content .sidemenu a').underline({
          color: "#909090", // underline color (default black)
          width: 1,         // underline thickness (default 1)
          duration: 250     // animation speed (default 500)
        });
        
        
        	$j('#submenu-col a').click(function(){
  	    
      var hasah = this.href;			
			hasah = hasah.replace(/^.*#/, '');
			
      $j.history.load(hasah);
			return false;              
       	});
        
        $j('.sidemenu a').each(function (){
          $j(this).css({ color: "#fff" });   
        });
      });
      
                   
    }       
       
  };
 
  // SET THEME /////////////////////////////// 
  function setTheme(type,site) { 
    	   
    idecko = type;
    if(activeSection != idecko){
       
      oldActiveSection = activeSection;
      activeSection = idecko;
      		 
      actualColor = window['menuColor' + idecko];
       
      hide_menu(); 
          
      $j('#submenu').slideDown(250);
      $j('#l0'+idecko).show();
      $j('#a0'+idecko).fadeIn(200);       
      
      var adresa = "ajax/getLogo.php?hash="+hash+"&menu="+idecko; 
      $j.post(adresa,{}, function(data) {$j('#logores').hide().html(data).slideDown(500);   });          
      
      adresa = "ajax/getSubmenu.php?hash="+hash+"&menu="+idecko;       
      $j.post(adresa,{}, function(data) {$j('#submenu').html(data); $j('#submenu #submenu-col a').css({'color': actualColor});  $j('#submenu-col').fadeIn(500); $j('#sub-icon').show("slow"); $j("#m0"+idecko).animate({ color: actualColor }, 300);  });    
      
      $j("#m0"+idecko).animate({ color: actualColor }, 300);
      
      adresa = "ajax/getLogin.php?hash="+hash+"&menu="+idecko; 
      $j.post(adresa,{}, function(data) {$j('#buttonlog').hide().html(data).slideDown(500);   });
      
      var border = (idecko-1)*190;
      $j("#graphic #carousel-small .border").animate({ opacity: 0.1 }, 500, function(){  $j(this).css( {backgroundPosition: "0px -"+border+"px"} ).animate({ opacity: 1.0 }, 500)   } );      
      
      var tweet = (idecko-1)*30;
      $j("#downmenu .tweet a").animate({ opacity: 0.1 }, 500, function(){  $j(this).css( {backgroundPosition: "0px -"+tweet+"px"} ).animate({ opacity: 1.0 }, 500)   } );      

      
      var sid = (idecko-1)*3;
      $j("#showline").css( {backgroundPosition: "0px -"+sid+"px"} ); 
      sid = (idecko-1)*20;
      $j("#footer .left .game-access1 a").css( {backgroundPosition: "0px -"+sid+"px"} ); 
      
      setSite(idecko,site,'1');           
    }       
  };

  // CAROUSEL ///////////////////////////////	
	function show_car() {
		if (next_car == 1) {
			$j('#article3').fadeOut(800);
			$j('#article2').fadeOut(800);
			$j('#article1').fadeIn(800);
			hide_next();
			$j('#car1a').animate({opacity: 1.0});
		}
		else if (next_car == 2) {
			$j('#article1').fadeOut(800);
			$j('#article3').fadeOut(800);
			$j('#article2').fadeIn(800);  
			hide_next();
			$j('#car2a').animate({opacity: 1.0});
		}
		else if (next_car == 3) {
			$j('#article2').fadeOut(800);
			$j('#article1').fadeOut(800);
			$j('#article3').fadeIn(800);
			hide_next();
			$j('#car3a').animate({opacity: 1.0});
			next_car = 0;
		};
		next_car++;		
	}
	
	function start_car() {running_car = setInterval(show_car,7000)};
	function stop_car() {clearInterval(running_car)};
	
  function hide_next(){
    $j('#car1a').animate({opacity: 0.1});
    $j('#car2a').animate({opacity: 0.1});
    $j('#car3a').animate({opacity: 0.1});
  }	
                                     
	//start_car();
	

