var hash = location.hash;
if (hash == "") {
location.hash="#selector";
}

var ht = "#selector";
var selectorMain = "homepage";
var blueoffset = 0;
var activeMenu = null;

function parseHashSelector(hash) {
	var pole = hash.split("-");
	var str = String(hash);
	var pozice = str.indexOf("#selector");
	var dotaz = {};
	if (pole.length==1 && pozice==0) {
		dotaz.maintyp="homepage";
		dotaz.typ=null;
		dotaz.page=null;
		loadPageFromHash(dotaz);
	}
	//["#selector", "obory", "statni_sprava", "93"]
	if (pole[0]=="#selector") {
		if (pole[1] != null && pole[1]!="" && pole[1]!=undefined) {
			dotaz.maintyp=pole[1];
			dotaz.typ=null;
			dotaz.page=null;
			if (pole[2] != null && pole[2]!="" && pole[2]!=undefined) {
				dotaz.typ = pole[2];
				dotaz.page=null;
				if (pole[3] != null && pole[3]!="" && pole[3]!=undefined) {
					dotaz.page = pole[3];
				}
			}
		}
		loadPageFromHash(dotaz);
	}
}


function loadPageFromHash(dotaz) {
	var sele = $("#menu-"+dotaz.maintyp);
	if (sele.size()>0) {
		$("#menu a").removeClass("active");
		sele.addClass("active");
	}
	if (dotaz.maintyp=="homepage") {
				selectorMain = "homepage";
				$.get("/obory.php",{ homepage: "true",tt: Math.random()},function(data) {
				$("#selector").html(data);
				$('#headerCarousel').cycle({
	        		fx:      "fade",
	       		 	speed:    2000, 
	        		timeout:  4000,
	        		cleartype:  true,
	        		cleartypeNoBg:  true
					}); 
				});
	}
	if (dotaz.maintyp=="obory" || dotaz.maintyp=="reseni") {
		if (dotaz.typ==null) {
				selectorMain = dotaz.maintyp;
				$.get("/"+dotaz.maintyp+".php",{ tt: Math.random()},function(data) {
				$("#selector").html(data);
				$('#headerCarousel').cycle({
	        		fx:      "fade",
	       		 	speed:    2000, 
	        		timeout:  4000,
	        		cleartype:  true,
	        		cleartypeNoBg:  true
					}); 
				});
		}
		else {
				if (dotaz.page==null) {
					selectorMain = dotaz.maintyp;
    				var type = dotaz.typ;
    				var urlDotaz = [];
    				urlDotaz["reseni"] = "/selector_reseni_sidebar.php";
    				urlDotaz["obory"] = "/selector_sidebar.php";
					$("#selector_header").html("<div class='loading'>Načítám</div>");

					$.get("/specializace_header.php",{ type:type, tt: Math.random()},function(data) {
					$("#selector_header").html(data); 
					$( "#slider-range" ).slider({
						range: 'min',
						value: 1000,
						min: 1,
						max: 2000,
						stop: function(event, ui) {
						vratVysledky(0,"omezovat");
						}
					});
					vratVysledky(0,"neomezovat");
						$.get(urlDotaz[dotaz.maintyp],{ type: type, tt: Math.random() },function(data) { 
							$("#tiskove-zpravy-a-nazory-odbornika").html(data);
						});
					});
				}
				else {
					var type = dotaz.maintyp;
					var type2 = dotaz.typ+"&page="+dotaz.page;
					var idp = dotaz.page;

					$.get("/specializace_header.php",{ type:type2, tt: Math.random()},function(data) {
						$("#selector_header").html(data);
						scroll("#selector_header");
					});
					if (dotaz.maintyp=="obory") {
						$.get("/specializace_sidebar.php",{ type:type2, tt: Math.random()},function(data) {
							$("#tiskove-zpravy-a-nazory-odbornika").html(data);
						});
						$.get("/ajax_vystup_stranky.php",{ stranka: idp, tt: Math.random()},function(data) {
							$("#vystup_projekty").html(data);
						});
					}
					else {
						$.get("/specializace_reseni_sidebar.php",{ type:type2, tt: Math.random()},function(data) {
							$("#tiskove-zpravy-a-nazory-odbornika").html(data);
						});
						$.get("/ajax_vystup_reseni_stranky.php",{ stranka: idp, tt: Math.random()},function(data) {
							$("#vystup_projekty").html(data);
						});
					}
					
				}
		}

	}

}

function scroll(id) {
	var off = 88;
	$('html,body').animate({
		scrollTop: $(id).offset().top - off
	}, 'slow');
}
function showLoader() {
//console.log(selectorMain);
var div = $('#loader');
var scrollTop = $(window).scrollTop();
div.css("top", ($(window).height() - div.height())/2 + scrollTop + 'px');
div.css("left", ($(window).width() - div.width())/2  + 'px');
//div.show();
}
function hideLoader() {
var div = $('#loader');
//div.hide();
}

function rozpeti(v) {
		return v;
}
function parseBoolean(b) {
if (b) {
return "1";
}
else {
return "0";
}
}
function vratVysledky(page,o) {
var v = $( "#slider-range" ).slider( "option", "value" );
var lidi = rozpeti(v);
//console.log(lidi);
var pole = [];
pole["obor"] = $("#typklienta").text();
pole["pocetlidi"] = lidi;
pole["job_aplikace_na_zakazku"] = parseBoolean($(".iconANZ").hasClass("active"));
pole["job_erp"] = parseBoolean($(".iconERP").hasClass("active"));
pole["job_business_intelligence"] = parseBoolean($(".iconBI").hasClass("active"));
pole["job_integrace_aplikaci"] = parseBoolean($(".iconIA").hasClass("active"));
pole["technology_ms"] = parseBoolean($(".ms").hasClass("active"));
pole["technology_or"] = parseBoolean($(".or").hasClass("active"));
pole["page"] = page;
if (o=="neomezovat") {
pole["neomezovat"] = "1";
}
if (pole["job_aplikace_na_zakazku"]==0 && pole["job_erp"]==0 && pole["job_business_intelligence"]==0 && pole["job_integrace_aplikaci"]==0 && pole["technology_ms"]==0 && pole["technology_or"]==0 ) {
pole["neomezovat"] = "1";
}

var str = "?";
for (var key in pole) {  
				str += key+"="+pole[key]+"&";  
} 
showLoader();
$.get("/ajax_vystup.php"+str+"tt="+Math.random(),function(data){
		hideLoader();
		$("#vystup_projekty").html(data);
});
}  

function vratVysledkyReseni(page,o) {
var v = $( "#slider-range" ).slider( "option", "value" );
var lidi = rozpeti(v);
//console.log(lidi);
var pole = [];
pole["reseni"] = $("#typklienta").text();
//pole["pocetlidi"] = lidi;
pole["statniSprava"] = parseBoolean($(".statniSprava").hasClass("active"));
pole["zdravotnictvi"] = parseBoolean($(".zdravotnictvi").hasClass("active"));
pole["podnikovaSfera"] = parseBoolean($(".podnikovaSfera").hasClass("active"));
pole["technology_ms"] = parseBoolean($(".ms").hasClass("active"));
pole["technology_or"] = parseBoolean($(".or").hasClass("active"));
pole["page"] = page;
if (o=="neomezovat") {
pole["neomezovat"] = "1";
}
if (pole["statniSprava"]==0 && pole["zdravotnictvi"]==0 && pole["podnikovaSfera"]==0 && pole["technology_ms"]==0 && pole["technology_or"]==0 ) {
pole["neomezovat"] = "1";
}

var str = "?";
for (var key in pole) {  
				str += key+"="+pole[key]+"&";  
} 
showLoader();

$.get("/ajax_vystup_reseni.php"+str+"tt="+Math.random(),function(data){
		hideLoader() 
		$("#vystup_projekty").html(data);
});
}
$(window).bind('hashchange', function() {
		var hash = location.hash;
		var str = String(hash);
		var pozice = str.indexOf("#selector");
		if (pozice==0) {
		$('html,body').animate({
			scrollTop: 0
		}, 'slow');
		}
	parseHashSelector(hash);
});

$(document).ready(function() {

	$("#show_more_references a").click(function(){
		if ($("#more_references:visible").size()==0) {
			$("#more_references").show();
			$("#show_more_references a").text("Sbalit reference");
		}
		else {
			scroll("#reference");
			$("#more_references").hide("slow");
			$("#show_more_references a").text("Více referencí");
		}
		return false;
	});

parseHashSelector(hash);

/*$(".checkHash").click(function(){
	var hash = location.hash;
	parseHashSelector(hash);
});*/



	$(".typeofjob a").live("click",function(){
	if ($(this).hasClass("active")) {
			$(this).removeClass("active");
	}
	else {
			$(this).addClass("active");	
	}
	vratVysledky(0,"omezovat");
	return false;
	}); 
	
	
	$(".company a").live("click",function(){
	if ($(this).hasClass("active")) {
			$(this).removeClass("active");
	}
	else {
			$(this).addClass("active");	
	}
	if (selectorMain == "obory") {
	vratVysledky(0,"omezovat");
	}
	if (selectorMain == "reseni") {
	vratVysledkyReseni(0,"omezovat");
	}
	return false;
	});  
	
	
	$(".pagination_ajax_selector a").live("click",function(){
	if ($(this).hasClass("specializace_strankovani")) {
			var url = $(this).attr("href")+"&tt="+Math.random();
			$.get(url,function(data){
									$("#vystup_projekty").html(data);
			});
	}
	else {
	var page = $(this).attr("rel");
	if (selectorMain == "obory" || selectorMain == "homepage") {
	vratVysledky(page,"neomezovat");
	}
	if (selectorMain == "reseni") {
	vratVysledkyReseni(page,"neomezovat");
	}
	}
	return false;
	});

$("#gp2 a").live("click",function(){
if ($(this).hasClass("active")) {
		$(this).removeClass("active");
}
else {
		$(this).addClass("active");	
}
vratVysledkyReseni(0,"omezovat");
return false;
}); 


		

        /*menu*/
        $('#menu .sub').mouseenter(function() {
                $(this).children('ul').show();
        }).mouseleave(function() {
                $('#menu .sub ul').hide();
        });    

        /*header carousel*/
        var ie = "fade";
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
         var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
         ie = "none";
        }
        
        $('#headerCarousel').cycle({
                fx:      "fade",
                speed:    2000, 
                timeout:  4000,
                cleartype:  true,
                cleartypeNoBg:  true
        }); 
        
              

        /*autoclear input*/
        var clearMePrevious = '';
        $('.clearOnClick').focus(function(){
                if($(this).val()==$(this).attr('title'))
                {
                        clearMePrevious = $(this).val();
                        $(this).val('');
                }
        });
        $('.clearOnClick').blur(function(){
                if($(this).val()=='')
                {
                        $(this).val(clearMePrevious);
                }
        });

        /*range slider*/
    /*$(".chooseselector a").live("click",function(){
    selectorMain = "obory"
    var type = $(this).attr("rel");
	$("#selector_header").html("<div class='loading'>Načítám</div>");
	$.get("/specializace_header.php",{ type:type, tt: Math.random()},function(data) {
	//$.get("/selector_header.php",{ type: type, tt: Math.random() },function(data) { 
		$("#selector_header").html(data); 
		$( "#slider-range" ).slider({
				range: 'min',
				value: 1000,
				min: 1,
				max: 2000,
				stop: function(event, ui) {
					vratVysledky(0,"omezovat");
				}
		});
		vratVysledky(0,"neomezovat");
		$.get("/selector_sidebar.php",{ type: type, tt: Math.random() },function(data) { 
				$("#tiskove-zpravy-a-nazory-odbornika").html(data);
		});
	
	});
	
	return false;
    });*/
    
    /*$(".choosereseni a").live("click",function(){
    selectorMain = "reseni";
    var type = $(this).attr("rel");
    $("#selector_header").html("<div class='loading'>Načítám</div>");
    $.get("/specializace_header.php",{ type:type, tt: Math.random()},function(data) {
    //$.get("/selector_reseni_header.php",{ type: type, tt: Math.random() },function(data) { 
    	$("#selector_header").html(data); 
    	$( "#slider-range" ).slider({
    			range: 'min',
    			value: 1000,
    			min: 1,
    			max: 2000,
    			stop: function(event, ui) {
    				vratVysledkyReseni(0,"omezovat");
    			}
    	});
    	vratVysledkyReseni(0,"neomezovat");
    	$.get("/selector_reseni_sidebar.php",{ type: type, tt: Math.random() },function(data) { 
    			$("#tiskove-zpravy-a-nazory-odbornika").html(data);
    	});
    
    });
    
    return false;
    });*/
    
    
    
    $("ul.chooseselector a").live({
      mouseover: function() {
		$("#headerCarousel").cycle("pause");
		var idecko = "#"+$(this).attr("rel");
		$("#headerCarousel .item").hide();
		$("#headerCarousel").find(idecko).show().css("opacity","1");
      },
      mouseout: function() {
		$("#headerCarousel").cycle("resume");
      }
    });
    
    $("ul.choosereseni a").live({
      mouseover: function() {
    	$("#headerCarousel").cycle("pause");
    	var idecko = "#"+$(this).attr("rel");
    	$("#headerCarousel .item").hide();
    	$("#headerCarousel").find(idecko).show().css("opacity","1");
      },
      mouseout: function() {
    	$("#headerCarousel").cycle("resume");
      }
    });
	
	
	////// specializace //////
	/*
	$(".specializace a").live("click",function(){
			var type = $(this).attr("rel");
			var url = $(this).attr("href")+"&ajax=true&tt="+Math.random();
			var url2 = $(this).attr("href");
			var pole = url2.split("type=");
			var type2 = pole[1];
			var id_page = url2.split("page=");
			var idp = id_page[1];

			$.get("/specializace_header.php",{ type:type2, tt: Math.random()},function(data) {
			$("#selector_header").html(data);
			scroll("#selector_header");
			});
			if ($(this).hasClass("vybrano_obor")) {
			$.get("/specializace_sidebar.php",{ type:type2, tt: Math.random()},function(data) {
			$("#tiskove-zpravy-a-nazory-odbornika").html(data);
			});
			$.get("/ajax_vystup_stranky.php",{ stranka: idp, tt: Math.random()},function(data) {
			$("#vystup_projekty").html(data);
			});
			}
			else {
			$.get("/specializace_reseni_sidebar.php",{ type:type2, tt: Math.random()},function(data) {
			$("#tiskove-zpravy-a-nazory-odbornika").html(data);
			});
			$.get("/ajax_vystup_reseni_stranky.php",{ stranka: idp, tt: Math.random()},function(data) {
			$("#vystup_projekty").html(data);
			});
			}
			
			return false;
	});*/
	
	$("a.slide").click(function(){
	$('#menu li a').removeClass('active');
	$(this).addClass('active');
	
	var h = $(this).attr("href");
	activeMenu = h;
	var p = h.split("#");
	ht = "#"+p[1];
	$(".main_blue").hide();
	scroll("#"+p[1]);
	});
	
	$("#show-obory, .backtoobory").live("click",function(){
	selectorMain = "obory";
	$.get("/obory.php",{ tt: Math.random()},function(data) {
	$("#selector").html(data);
	$('#headerCarousel').cycle({
	        fx:      "fade",
	        speed:    2000, 
	        timeout:  4000,
	        cleartype:  true,
	        cleartypeNoBg:  true
	}); 
	//Cufon.replace('#selector_header h2, #selector_header h3', { hover: true} );
	});
	});
$("#show-reseni, .backtoreseni").live("click",function(){
selectorMain = "reseni";
$.get("/reseni.php",{ tt: Math.random()},function(data) {
$("#selector").html(data);
$('#headerCarousel').cycle({
        fx:      "fade",
        speed:    2000, 
        timeout:  4000,
        cleartype:  true,
        cleartypeNoBg:  true
}); 
});
});
	
	function pagerFactory(idx, slide) {
					var s = "";
					var html = "";
					var text = "";
					text = $(slide).find("h2").attr("data-menu")
					if (text == "" || text == undefined) {
					text = $(slide).find("h2").text();
					}
	                return "<div class='pager_a' "+s+"><a href=\"#\">"+text+"</a></div>";
	};
	
	$(".small_menu a").live("click",function(){
	$(".small_menu a").removeClass("active");
	$(".main_blue").hide();
	$(this).addClass("active");
	var idecko = $(this).parent().parent().attr("data-target");
	ht = "#"+idecko.replace("blue-", "");
	scroll(ht);
	var t = idecko + "-data";
	var url = $(this).attr("href")+"&ajax=true&tt="+Math.random();
	$.get(url,function(data) {
	$("#"+t).html(data);
	$("#"+idecko).slideDown();
	var p = '#'+idecko+" .sipkyleft";
	var n = '#'+idecko+" .sipkyright";
	var pg = '#'+idecko+" .pager";
	$('#'+idecko).find(".items").cycle({
	        fx:      'scrollHorz',
	        speed:    2000, 
			timeout:  0,
			pause:    1,
			pager:   pg,
			prev:    p,
			next:    n,
			pagerAnchorBuilder: pagerFactory 
	});   
	});
	return false;
	});
	
	$("a#o-nas-a").live("click",function(){
	var idecko = $(this).attr("rel");
	var t = idecko + "-data";
	$(".small_menu a").removeClass("active");
	$("#o-nas .small_menu a:eq(0)").addClass("active");
	var url = $("#"+idecko+"-menu").find("li:eq(0)").find("a").attr("href")+"&ajax=true&tt="+Math.random();
	$(".main_blue").slideUp();
	$.get(url,function(data) {
	$("#"+t).html(data);
	$("#"+idecko).slideDown();
	var p = '#'+idecko+" .sipkyleft";
	var n = '#'+idecko+" .sipkyright";
	var pg = '#'+idecko+" .pager";
	$('#'+idecko).find(".items").cycle({
	        fx:      'scrollHorz',
	        speed:    2000, 
			timeout:  0,
			pause:    1,
			pager:   pg,
			prev:    p,
			next:    n,
			pagerAnchorBuilder: pagerFactory  
	}); 
	   
	});
	
	});

	
	$(".close a").live("click",function(){
	$(this).parent().parent().parent().slideUp();
	$(this).parent().parent().html("");
	return false;
	});
	$(".print a").live("click",function(){
	var url = $(this).attr("href");
	window.open(url);
	return false;
	});
	
	// activate lightboxu s pripadovkou
	$("#vystup_projekty .item a").live("click",function(){
	showLoader();
	ht = "#selector";
	var url = $(this).attr("href")+"&ajax=true&tt="+Math.random();
	var urlPrint = $(this).attr("href")+"&print=true";
	$.get(url,function(data) {
	hideLoader();
	html = data + '<div class="print"><a href="'+urlPrint+'">Print</a></div><div class="close"><a href="#">Zavřít</a></div>';
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px').show();
	$("#lightboxInner2").html(html).show();
	$("#lightbox").fadeIn();
	scroll("#pripadovka_header");
	});
	return false;
	});
	
	//aktivace lightboxu - obecne
	$("a.to-lightbox").live("click",function(){
	showLoader();
	ht = "#"+$(this).attr("data-slideto");
	var url = $(this).attr("href")+"?ajax=true&tt="+Math.random();
	var urlPrint = $(this).attr("href")+"?print=true";
	$.get(url,function(data) {
	hideLoader();
	html = data + '<div class="print"><a href="'+urlPrint+'">Print</a></div><div class="close"><a href="#">Zavřít</a></div>';
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px').show();
	$("#lightboxInner2").html(html).show();
	$("#lightbox").fadeIn();
	scroll("#pripadovka_header");
	});
	return false;
	});
	
	$("a.playvideo").live("click",function(){
	var idvideo = $(this).attr("rel");
	var kam = $(this).attr("data-kam");
	ht = "#"+kam;
	var data = '<div id="videoplayer" style="padding-top:40px;padding-bottom:0px;background:black;"><iframe width="1000" height="538" src="https://www.youtube.com/embed/'+idvideo+'?rel=0&amp;autoplay=1&amp;hd=1" frameborder="0" allowfullscreen></iframe></div>';
	html = data + '<div class="close"><a href="#">Zavřít</a></div>';
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px').show();
	$("#lightboxInner2").html(html).show();
	$("#lightbox").fadeIn();
	scroll("#videoplayer");
	return false;
	});
	
	$(".reference-box").live("click",function(){
	showLoader();
	ht = "#reference";
	var url = $(this).find("a").attr("href")+"&ajax=true&tt="+Math.random();
	var urlPrint = $(this).find("a").attr("href")+"&print=true";
	$.get(url,function(data) {
	hideLoader();
	html = data + '<div class="print"><a href="'+urlPrint+'">Print</a></div><div class="close"><a href="#">Zavřít</a></div>';
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px').show();
	$("#lightboxInner2").html(html).show();
	$("#lightbox").fadeIn();
	scroll("#pripadovka_header");
	});
	return false;
	});
	
	$("#volne_pozice a").live("click",function(){
	showLoader();
	ht = "#kariera";
	var url = $(this).attr("href")+"?ajax=true&tt="+Math.random();
	var urlPrint = $(this).attr("href")+"&print=true";
	$.get(url,function(data) {
	hideLoader();
	html = data + '<div class="print"><a href="'+urlPrint+'">Print</a></div><div class="close"><a href="#">Zavřít</a></div>';
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px').show();
	$("#lightboxInner2").html(html).show();
	$("#lightbox").fadeIn();
	scroll("#pripadovka_header");
	});
	return false;
	});
	
	
	
	function closeLightbox() {
	$("#lightbox").fadeOut();
	$("#lightboxInner2").html("").show();
	scroll(ht);
	}
	
	$("#lightboxInner2 .close a").live("click",function(){
	closeLightbox();
	return false;
	});
	
	$("#shadow").click(function(){
	closeLightbox();
	return false;
	});
	
	$(document).keyup(function(e) {
	  if (e.keyCode == 27) { closeLightbox(); }
	});
	
       		
});
$(window).load(function() {
var vyska = $("#body").height();
$("#shadow").css("height",vyska+"px");
});
function zmena() {
	$("#lightboxInner").css("left", ($(window).width() - $("#lightboxInner").width())/2  + 'px');
	}

window.onresize = zmena;
