var jazyk = 'cz';
var root = location.protocol + '//' + location.host + '/';

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 check_jazyka(){
	if($(".onas")[0] == undefined && getCookie("anglicky") == 0){
		/* refresh do CZ */
		location.reload();
	}
	
	if($(".onas2")[0] == undefined && getCookie("anglicky") == 1){
		/* refresh do EN */
		location.reload();
	}
}

function titulek(titul)
{
switch(titul){
 case '3d_grafika': document.title = "3D Grafika a vizualizace";document.cookie = "anglicky=0; path=/";break;
 case '2d_grafika': document.title = "2D Grafika";document.cookie = "anglicky=0; path=/";break;
 case 'film_a_animace': document.title = "Film a animace";document.cookie = "anglicky=0; path=/";break;
 case 'reklama': document.title = "Online reklama";document.cookie = "anglicky=0; path=/";break;
 case 'flash_animace_a_hry': document.title = "Flash hry a animace";document.cookie = "anglicky=0; path=/";break;
 case 'vizitky_plakaty_a_dalsi_tiskoviny': document.title = "Tiskoviny a prepress";document.cookie = "anglicky=0; path=/";break;
 case 'portfolio': document.title = "Webdesign a tvorba WWW";document.cookie = "anglicky=0; path=/";break;
 case 'kontakt': document.title = "Kontakt";document.cookie = "anglicky=0; path=/";break;
 case 'o_nas': document.title = "O nás";document.cookie = "anglicky=0; path=/";break;
 case 'portfolio': document.title = "Portfolio";document.cookie = "anglicky=0; path=/";break;
 case 'fotograficke_sluzby': document.title = "Fotografické služby a digitalizace";document.cookie = "anglicky=0; path=/";break;
 case 'kalibrace': document.title = "Kalibrace monitoru";document.cookie = "anglicky=0; path=/";break;
 case 'webdesign': document.title = "Webdesign";document.cookie = "anglicky=0; path=/";break;
 case 'cenik': document.title = "Ceny služeb";document.cookie = "anglicky=0; path=/";break;
 case 'kontakt': document.title = "Kontakt";document.cookie = "anglicky=0; path=/";break;
 case 'kontaktni_formular': document.title = "Kontakt";document.cookie = "anglicky=0; path=/";break;
 
 case '3d_graphics': document.title = "3D Grafics and vizualization";document.cookie = "anglicky=1; path=/";break;
 case '2d_graphics': document.title = "2D Grafics";document.cookie = "anglicky=1; path=/";break;
 case 'movie_and_animation': document.title = "Movie and animation";document.cookie = "anglicky=1; path=/";break;
 case 'advertisment': document.title = "Online advertisment";document.cookie = "anglicky=1; path=/";break;
 case 'flash_games_and_animation': document.title = "Animation and Games";document.cookie = "anglicky=1; path=/";break;
 case 'prints': document.title = "Stationery a prepress";document.cookie = "anglicky=1; path=/";break;
 case 'webdesign': document.title = "Webdesign a WWW creation";document.cookie = "anglicky=1; path=/";break;
 case 'portfolio-en': document.title = "Portfolio";document.cookie = "anglicky=1; path=/";break;
 case 'contact': document.title = "Contact";document.cookie = "anglicky=1; path=/";break;
 case 'about': document.title = "Profile";document.cookie = "anglicky=1; path=/";break;
 case 'photographics_services': document.title = "Photographics services and digitalization";document.cookie = "anglicky=1; path=/";break;
 case 'monitor_calibration': document.title = "Monitor calibration";document.cookie = "anglicky=1; path=/";break;
 case 'webdesign': document.title = "Webdesign";document.cookie = "anglicky=1; path=/";break;
 case 'prices_and_services': document.title = "Prices of services";document.cookie = "anglicky=1; path=/";break;
 case 'contact_form': document.title = "Contact";document.cookie = "anglicky=1; path=/";break;
 
 default:	if(jazyk == 'cz'){document.title = "O nás";}
 			else{document.title = "Profile";}
 			break;
}}

$(document).ready(function() {

var root = location.protocol + '//' + location.host + '/';

      $(".odkazy a").each(function()
      {
        $(this).click(function(event)
        {
         event.preventDefault();
         var vcesta = this.href.replace(root,"");
         nacti(vcesta);
		 titulek(vcesta);
         });
		 
		 $(this).hover(function(){
		 	$(this).css( { 'color' : '#C2C2C2' } );
		 }
		 ,
		 function()
		 {
		 	//alert("#"+this.href.replace(root,"") + " != " + window.location.hash);
			var cst = window.location.hash;
			if(cst == '')cst = "#";
		 	if("#"+this.href.replace(root,"") != cst)
			$(this).css( { 'color' : '#FFF' } );
		 }
		 );
      });
	  
	  var cesta = window.location.href.replace(root,"");
	  if(cesta[0] == '#')
	  {
	  	nacti(cesta.replace("#",""));
	  }
      });
      function nacti(strana)
      {
        window.location.hash = strana;
		//	stranky se meni pomoci hashchange
      }
      function zmenrec(rec)
      {
	  	var root = location.protocol + '//' + location.host + '/';
        //alert(rec);
        if(rec=="english_")
		{
        	document.cookie = "anglicky=1; path=/";
			jazyk = 'en';
		}
        if(rec=="cesky_")
		{
        	document.cookie = "anglicky=0; path=/";
			jazyk = 'cz';
		}
		//alert(root);
        window.location = root;
      }
      function affilate()
      {
        $(".newg").load("affilate_web4u_google.php");
      }

      function nactis(strana)
      {
        //alert(strana);
        $(".obsah").empty().html('<p class="bg-load" style="text-align: center; margin:0; padding:0;"><img src="ajax-loader.gif" /></p>');
        $(".bg-load").hide();
        $(".bg-load").fadeIn("fast", function(){
        //window.location.hash = strana;
        $(".obsah").load(strana);
		titulek(strana);
        //affilate();
      });
      }

      function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
}
fix_flash();

	// s hashchange zmenit stranku (tlacitka vpred a zpet v historii)
$(window).hashchange( function(){
		var strana = window.location.href.replace(root+"#","");
		titulek(strana);
		check_jazyka();
		//alert(strana);
        $(".obsah").empty().html('<p class="bg-load" style="text-align: center; margin:0; padding:0;"><img src="ajax-loader.gif" /></p>');
        $(".bg-load").hide();
        $(".bg-load").fadeIn("fast", function(){
        $(".obsah").load("obsah.php", { 'cesta': strana });
		
		$(".odkazy a").css( {'color' : '#FFF'} );
		$(".links a").css( {'color' : '#FFF'} );
		$('.odkazy a[href="'+strana+'"]').css( { 'color' : '#C2C2C2' } );
		$('.links a[href="'+strana+'"]').css( { 'color' : '#C2C2C2' } );
		if( strana == "" )$('.odkazy a').first().css( { 'color' : '#C2C2C2' } );
		if( strana == window.location.href )$('.odkazy a').first().css( { 'color' : '#C2C2C2' } );
		
        affilate();
      });
  });

var cesta = window.location.href.replace(root,"");
if(cesta != "" && cesta[0] != '#')
{
  window.location.replace(root + "#" + cesta);
}

$(document).ready(function(){
	$(window).hashchange();
});

