jQuery(document).ready(function() {

//HOVER MENU
    jQuery("#menu a").mouseover(function() {
        jQuery(this).addClass("hover");
    })
    jQuery("#menu a").mouseout(function() {
        jQuery(this).removeClass("hover");
    })

    var pageBtn = "#" + jQuery.getUrlVars()["page"] + "Btn";

    if (pageBtn == "#undefinedBtn") pageBtn = "#homeBtn";

    jQuery(pageBtn).addClass("active");

    if (jQuery("#portfolioBtn").hasClass("active")) {
        jQuery("#subMenu").css("visibility", "visible");
        jQuery("#header").animate({height: "111px"},500);
        jQuery("#subMenu").show();
    }



//HOVER SUBMENU
    var subpageBtn = "#" + jQuery.getUrlVars()["subpage"] + "Btn";
    jQuery(subpageBtn).addClass("active");

//PRIDANIE NAZVU SUBMENU DO TRIEDY PRE POSUN OBRAZKA DO STREDU
	if (subpageBtn == "#reklamnePolepyBtn") {
		jQuery('#containerMain').addClass('polepy');
	}

//HOVER NA SIPKY V PORTFOLIU
    jQuery("#containerSlide .arrow.Left").hover(
        function(){
            jQuery(this).attr("src","./files/arrow_selected.png");
        },
        function(){
            jQuery(this).attr("src","./files/arrow.png");
        }
    );

    jQuery("#containerSlide .arrow.Right").hover(
        function(){
            jQuery(this).attr("src","./files/arrowR_selected.png");
        },
        function(){
            jQuery(this).attr("src","./files/arrowR.png");
        }
    );
//SLIDER
    var border =  jQuery("#slider > li").size()-7;
    var position = 0;

    jQuery("#containerSlide .arrow.Right").click(function(){
       if (position < border) {
            jQuery("#slider").animate({'left' : "-=114px"});
            position += 1;
        }
    });

    jQuery("#containerSlide .arrow.Left").click(function(){
        if (position > 0){
            jQuery("#slider").animate({'left' : "+=114px"});
            position -= 1;
        }
    });

//HOVER NA MINIATURI V PORTFOLIU A HOME
    jQuery(".boxSlide").hover(
        function(){
            jQuery(this).css('background-image', 'url(./files/nahlad_home_hover.png)');
        },
        function(){
            jQuery(this).css('background-image', 'url(./files/nahlad.png)');
        }
    );


//ZMENA OBRAZKU V PORTFOLIU A HOME A NACITANIE INFA V HOME
    jQuery(".boxSlide .boxInner img").click(function(){
        var path = jQuery(this).attr("src").replace("_thumb.",".");
		var realhref  = jQuery(this).prev().attr('href');
		var realrel = jQuery(this).prev().attr('rel');
		var title = jQuery(this).attr('title');
		

        var oldImg =jQuery("#containerMain .boxInner a img");
        var newImg = jQuery('<img />').attr('src',path);
		
		

		/*
		jQuery.post('loadHref.php', {imgsrc: path},function(data){
			imghref = data;
			if (imghref!=path) lightbox='';
			else lightbox='lightbox';
			});*/
		
		jQuery("#containerMain .boxInner a").attr({href:realhref,rel:realrel,title:title})
		
        newImg.load(function(){
           jQuery("#containerMain .boxInner a").prepend(newImg);		   
          oldImg.fadeOut("slow",function(){oldImg.remove();});
        })

        if (pageBtn == "#homeBtn"){
            var name = jQuery(this).attr("title");
            jQuery.post('loadInfo.php', {name: name},function(info){jQuery("#infoBox").html(info);});

        }

    });

		
	


	
//VYMAZANIE SIPIEK 
    if (jQuery("#slider > li").size() <= 7){
        jQuery(".arrow").remove();
    }


//HOVER NA LOGA VO FOOTERI
    jQuery("#logo_ep,#logo_fb")
        .mouseover(function() {
            var src = jQuery(this).attr("src").match(/[^\.]+/) + "_hover.png";
            jQuery(this).attr("src", src);
        })
        .mouseout(function() {
            var src = jQuery(this).attr("src").replace("_hover", "");
            jQuery(this).attr("src", src);
        });

//PRESMEROVANIE LOGA VO FOOTERI
    jQuery("#logo_ep").click(function(){
        window.location = "http://epresov.com";
    });
    jQuery("#logo_fb").click(function(){
        window.location = "http://niosart.sk";
    });


});



function slide(){
        jQuery("#subMenu").hide();
        jQuery("#header").animate({height: "84px"},1000,function(){return true;});

}


jQuery.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return jQuery.getUrlVars()[name];
  }
});
