function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function sendToCart(link,open) {
	var vo = window.opener;

	if (open==1) { window.location.href = link; }

	if (!vo.closed) { 
		vo.location.href = link; 
		window.close();
	} else { 
		var fs = window.open(link,"_blank"); 
		fs.focus();
	}
}

function winopen(link) {
	var fs = window.open(link, "offer", "width=790,height=700,scrollbars=yes,resizable=yes"); 
	fs.focus();
}

$(document).ready(function(){

    $("ul#rmenu>li").hover(function() { 
			$(this).addClass("over");
			$(this).find("div").dropShadow({left:0,top:4,blur:2,opacity:0.5}); },function(){ 
			$(this).removeClass("over"); 
			$(this).find("div").removeShadow(); 
	});

	$("ul#pmenu>li").hover(
		function() { 
			var w = $(this).width()-5;
			if (w<120) { w = 110; }
			$(this).find("ul").css("width",w);
			$(this).addClass("over"); 
		},
		function() { $(this).removeClass("over"); }
	);

    $("ul.s>li").hover(function() { 
			$(this).addClass("hover"); },function(){ 
			$(this).removeClass("hover"); });
 
	$("ul.reference").find("li").click(function() { window.location.href = $(this).find("a").attr("href"); });
	$("ul.akce").find("li").click(function() { window.location.href = $(this).find("a").attr("href"); });
	$("ul.img").find("li").click(function() { window.location.href = $(this).find("a").attr("href"); });

    externalLinks();	
	markPrice();

	
	$('a[href*=#]').click(function() {
	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	    && location.hostname == this.hostname) {
	      var $target = $(this.hash);
	      $target = $target.length && $target 
	      || $('[name=' + this.hash.slice(1) +']');
	      if ($target.length) {
	        var targetOffset = $target.offset().top;
	        $('html,body')
	        .animate({scrollTop: targetOffset}, 1000);
	       return false;
	      }
	    }
	});		
}); 

function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, resizable=yes, scrollbars=yes');
}


function openWindow(path, name, width, height) {

   var winl = (screen.width - width) / 2;
   var wint = (screen.height - height) / 2;

   style = eval("'status=no,width="+width+",height="+height+",left="+winl+",top="+wint+",resizable=no,menubar=no,scrollbars=yes,toolbar=no'");
   window.open(path, name, style) ;
}


function markPrice() {
	$(".priceGet").click(function() { 
		showPrice($(this)); 
	});
	$(".priceGetTEST").click(function() { 
		showPriceTEST($(this)); 
	});
}

function markPriceCat() {
	$(".videoGet").click(function() {
		$.fn.colorbox({open:true, transition:"fade", width:"362px", height:"330px", href:$(this).attr("rel")});

	});
	$(".priceGetC").click(function() { 
		showPriceCat($(this)); 
	});
}
function showPriceTEST(me) {

	var sTop = $(window).scrollTop();
	var sOff = me.offset().top;
	if (sOff-sTop<160) {
		off = 180-(sOff-sTop);
		//$(window).scrollTop(sTop-off)
		$('html,body').animate({scrollTop: sTop-off}, 400);
	}


	kod = me.attr("rel");
	aj = me.next();

	$("span.loader").css("z-index","90");

	if (aj.attr("class")!="loader") {
		me.after("<span class=\"loader\"></span>");
		n = me.next();

		n.load("/ajax/?kod="+escape(kod),{limit: 25}, function() { 

			n.find("div.cartAjax").draggable( { 
				start: function() { 
					$(".loader").css("z-index","90");
					$(this).parent().css("z-index","100"); 
				} 
			}); 
			n.find("div.cartAjax").click( function() { 
				$(".loader").css("z-index","90");
				$(".loader").css("background","#fff");
				$(this).parent().css("z-index","100"); 
				$(this).parent().css("background","#000");
			}); 

			n.find("div.cartAjax").slideDown(300); 
			n.css("z-index","100");

			n.find("span.cClose>a").click(function() { 
				hidePrice($(this)); 
			});


		} );

	} else {
		me.next().css("z-index","100");
		me.next().find("div.cartAjax").slideDown(300); 
	}
	
}

function showPrice(me) {

	var sTop = $(window).scrollTop();
	var sOff = me.offset().top;
	if (sOff-sTop<160) {
		off = 180-(sOff-sTop);
		//$(window).scrollTop(sTop-off)
		$('html,body').animate({scrollTop: sTop-off}, 400);
	}


	kod = me.attr("rel");
	aj = me.next();

	$("span.loader").css("z-index","90");

	if (aj.attr("class")!="loader") {
		me.after("<span class=\"loader\"></span>");
		n = me.next();

		n.load("/ajax/?kod="+escape(kod),{limit: 25}, function() { 

			n.find("div.cartAjax").draggable( { 
				start: function() { 
					$(".loader").css("z-index","90");
					$(this).parent().css("z-index","100"); 
				} 
			}); 
			n.find("div.cartAjax").click( function() { 
				$(".loader").css("z-index","90");
				$(".loader").css("background","#fff");
				$(this).parent().css("z-index","100"); 
				$(this).parent().css("background","#000");
			}); 

			n.find("div.cartAjax").slideDown(300); 
			n.css("z-index","100");

			n.find("span.cClose>a").click(function() { 
				hidePrice($(this)); 
			});


		} );

	} else {
		me.next().css("z-index","100");
		me.next().find("div.cartAjax").slideDown(300); 
	}
	
}

function showPriceCat(me) {

	kod = me.attr("rel");
	aj = me.find(".loader");

	$("span.loader").css("z-index","90");

	if (aj.attr("class")!="loader") {
		me.append("<span class=\"loader\"></span>");
		n = me.find(".loader");

		n.load("/ajax/?kod="+escape(kod),{limit: 25}, function() { 
			
			n.find("div.cartAjax").draggable( { 
				start: function() { 
					$(".loader").css("z-index","90");
					$(this).parent().css("z-index","100"); 
				} 
			}); 
			n.find("div.cartAjax").click( function() { 
				$(".loader").css("z-index","90");
				$(".loader").css("background","#fff");
				$(this).parent().css("z-index","100"); 
				$(this).parent().css("background","#000");
			}); 

			n.find("div.cartAjax").slideDown(300); 
			n.css("z-index","100");

			n.find("span.cClose>a").click(function() { 
				hidePrice($(this)); 
			});


		} );

	} else {
		me.find(".loader").css("z-index","100");
		me.find(".loader").find("div.cartAjax").slideDown(300); 
	}
	
}

function hidePrice(me) {
	me.parent().parent().parent().slideUp(100,function() { $(this).parent().remove(); }); 	
}
function hidePriceA(me) {
	$("#"+me).parent().parent().parent().parent().slideUp(100,function() { $(this).parent().remove(); }); 	
}

function hideSBanner() {
	$("#cpbann").hide();
}

