var hovercount = 3000;
$(document).ready(function(){
	/*$(".div-icon-cart").click(function (){
		$(this).find(".div-cart-hover").fadeIn("fast");
	});*/
	
	/*
	$(".myinvoices-line-even, .myinvoices-line-odd").click(function(){
		$(this).find("div.myinvoices-line-content-even, div.myinvoices-line-content-odd").slideToggle(300);
		$(this).siblings().find("div.myinvoices-line-content-even,div.myinvoices-line-content-odd").slideUp("slow");
	});
	*/
	
	
	/*
	$(".myinvoices-line-odd").click(function()
	{
	    $(this).next("div.myinvoices-line-content-odd").slideToggle(300).siblings("div.myinvoices-line-content-odd").slideUp("slow");
	});
	*/
	/*
	$(document).mousedown(function(){
		$(".div-cart-hover:visible").fadeOut("fast");
	});
	*/

	$("a[href]").each(function() {
		$(this).attr("href", $(this).attr("href").replace(/https:/gi, 'http:'));
	});

	var currentTime = new Date()
	//var q = $.parseQuery();
	//q['ts'] = currentTime.getTime();
	//$.get(burl + 'index.php?id=190', q, function(data) {
	
	//var lburl = burl.replace(/https:/, "http:");
	
	$.get(burl + 'loginform/', {ts: currentTime.getTime()}, function(data) {
		$('#div-toplogin').html(data.replace(/src="http:/gi, 'src="https:'));
	});


	if($(".div-minibasket")) {
		$.post(burl + 'index.php?eID=minibasket',{} , function(data) {
			$('#div-minibasket-content').html(data);
		});
	}

	if($(".div-bannerad")) {
		$.post(burl + 'banner-reklame/',{ts: currentTime.getTime()} , function(data) {
			if (burl.indexOf("https://") == 0) {
				$('.div-bannerad').html(data.replace(/http:/gi, "https:"));
			}
			else {
				$('.div-bannerad').html(data);
			}
		});
	}
	
	$('.add-to-basket-sale').click(function() {
		//$.post('/index.php?eID=minibasket',{request: 'add', productId: $(this).attr('muvio:productid'), productPrice: $(this).attr('muvio:price'), productTitle: $(this).attr('muvio:title')}, function(data) {
		$.post(burl + 'index.php?eID=minibasket',{request: 'add', productId: $(this).attr('muvio:productid')}, function(data) {
			$('#div-minibasket-content').html(data);
		});

		$(this).parent().parent().css("z-index", hovercount++);
		
		$(this).css("z-index", hovercount++);
		//$(this).find(".div-cart-hover").fadeIn("fast");
		$(this).find(".div-cart-hover").fadeIn("fast").animate({opacity: 1.0}, 3000).fadeOut('fast');
	});
	
	
	$('.add-to-basket-rent').click(function() {
		//$.post('/index.php?eID=minibasket',{request: 'add', productId: $(this).attr('muvio:productid'), productPrice: $(this).attr('muvio:price'), productTitle: $(this).attr('muvio:title')}, function(data) {
		$.post(burl + 'index.php?eID=minibasket',{request: 'add', productId: $(this).attr('muvio:productid')}, function(data) {
			$('#div-minibasket-content').html(data);
		});

		$(this).parent().parent().css("z-index", hovercount++);

		$(this).css("z-index", hovercount++);
		//$(this).find(".div-cart-hover").fadeIn("fast");
		$(this).find(".div-cart-hover").fadeIn("fast").animate({opacity: 1.0}, 3000).fadeOut('fast');
	});
	
	$(".a-close-cart-hover").click(function (){
		$(this).parent().fadeOut("fast");
		return false;
	});
	$(".div-product-also-item-img, .div-cat-topitem-img, .div-catitem-img, .div-listitem-img, .div-recommenditem-img, .div-catitem-nopic-speccol-title").hover(function(e){
		var hover_obj = $(this).parent().find(".div-movie-hover");
		$("#div-aa-hover").html(hover_obj.html());
		$("#div-aa-hover").css("z-index", hovercount++).css("left", $(this).offset().left+($(this).width()+4)).css("top", $(this).offset().top).css("display","block");
		//$(this).parent().css("z-index", hovercount++);
		//$(this).parent().find(".add-to-basket").css("z-index", "");
		//hover_obj.css("z-index", hovercount++);
		//hover_obj.fadeIn("fast");
	},function(){
		//var hover_obj = $(this).parent().find(".div-movie-hover");
		//hover_obj.fadeOut("fast");
		$("#div-aa-hover").css("display","none");
	});
	$(".div-top10row").hover(function(e){
		var hover_obj = $(this).find(".div-movie-hover");
		$("#div-aa-hover").html(hover_obj.html());
		$("#div-aa-hover").css("z-index", hovercount++).css("left", $(this).offset().left-(hover_obj.width()+4)).css("top", $(this).offset().top).css("display","block");
	},function(){
		$("#div-aa-hover").css("display","none");
	});

	$(".div-narrowcol .div-recommenditem").hover(function(e){
		var hover_obj = $(this).find(".div-movie-hover");
		$("#div-aa-hover").html(hover_obj.html());
		$("#div-aa-hover").css("z-index", hovercount++).css("left", $(this).offset().left-(hover_obj.width()+8)).css("top", $(this).offset().top).css("display","block");
	},function(){
		$("#div-aa-hover").css("display","none");
	});

	$("#div-dd-genre .div-dropdown-col .div-dropdown-links .div-dropdownmenu-link").hover(function(e){
		$(this).css("background-color","#ea6921");
	},function(){
		$(this).css("background-color","transparent");
	});

	$("#div-dd-support .div-dropdown-col .div-dropdown-links .div-dropdownmenu-link").hover(function(e){
		$(this).css("background-color","#ea6921");
	},function(){
		$(this).css("background-color","transparent");
	});

/*
	$(".div-catitem-nopic-speccol-title .div-catitem-nopic-title a").hover(function(e){
		var hover_obj = $(this).find(".div-movie-hover");
		$("#div-aa-hover").html(hover_obj.html());
		$("#div-aa-hover").css("z-index", hovercount++).css("left", $(this).offset().left+250).css("top", $(this).offset().top-5).css("display","block");
	},function(){
		$("#div-aa-hover").css("display","none");
	});
*/
/*
	$(".div-catitem-nopic-odd").hover(function(e){
		var hover_obj = $(this).find(".div-movie-hover");
		$("#div-aa-hover").html(hover_obj.html());
		$("#div-aa-hover").css("z-index", hovercount++).css("left", $(this).offset().left-(hover_obj.width()+4)).css("top", $(this).offset().top).css("display","block");
	},function(){
		$("#div-aa-hover").css("display","none");
	});
*/
	//$("body").addClass("thisisbody").prepend('<div style="display: none;" id="div-aa-hover" class="div-movie-hover"><div class="div-movie-hover-title">Apocalypto</div><div class="div-movie-hover-content"><a href="http://www.muvio.dk/nc/enkelt-visning/?tx_bee3muvio_pi6%5Bvideo%5D=6062"><img width="113" height="174" border="0" src="http://muvio.demo.safeplayer.dk/i000017AE005A4697.jpg"/></a>description 1</div><div class="div-movie-hover-info"><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">Original titel:</div><div class="div-movie-hover-info-value">Apocalypto</div></div><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">Genre:</div><div class="div-movie-hover-info-value">Action</div></div><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">År:</div><div class="div-movie-hover-info-value">2006</div></div><div class="div-clr"></div></div><div class="div-movie-hover-footer"><img src="http://www.muvio.dk/fileadmin/templates/dk.muvio/images/muvio_hover_bottom.gif"/></div></div>');
	
	$("body").addClass("thisisbody").prepend('<div style="display: none;" id="div-aa-hover" class="div-movie-hover"><div class="div-movie-hover-title"></div><div class="div-movie-hover-content"></div><div class="div-movie-hover-info"><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">Original titel:</div><div class="div-movie-hover-info-value"></div></div><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">Genre:</div><div class="div-movie-hover-info-value"></div></div><div class="div-movie-hover-info-row"><div class="div-movie-hover-info-title">År:</div><div class="div-movie-hover-info-value">2006</div></div><div class="div-clr"></div></div><div class="div-movie-hover-footer"></div></div>');
	//$("div#div-dd-genre").load("/index.php?eID=genredropdown");
	//$("div#div-dd-support").load("/index.php?eID=supportdropdown");
	/*
	$(".div-product-spec-icons-mov a").click(function (){
		preview_player("flash/player_trans.swf", "<playlist><video><title>video 1</title><url>video1.flv</url></video></playlist>");
	});
	*/
	if($("body").hasClass("lightbox")){
		//$(".td-popup-container-content").height(($(".div-popup-container").height()-$(".div-popup-container-info").height())-25);
	}
});
$(function() {
    $(window).bind('resize', function() {
    	preview_player_arrange();
    	popup_arrange();
    }).trigger('resize');
	$(window).bind('scroll', function() {
		preview_player_arrange();
		popup_arrange();
	}).trigger('scroll');
});
function show_click_layer(obj){
	return;
	//$(obj).css("z-index", hovercount++);
	//setTimeout(function(){$(obj).find(".div-cart-hover").fadeOut('fast')},5000);
	//$(obj).find(".div-cart-hover").fadeIn("fast");
}
function preview_player_arrange(){
	//$(".div-preview-overlay").css("z-index", hovercount++);
	//$("#div-popup").css("z-index", hovercount++);
	//$("#div-preview-mov").css("z-index", hovercount++);
	//$("#div-preview-mov").css("left", ($(document).width()-395)/2);
	$("#div-preview-mov").css("left", ($(document).width()-660)/2);
	//$("#div-preview-mov").css("top", (($(window).height()-295)/2)+$(document).scrollTop());
	$("#div-preview-mov").css("top", (($(window).height()-420)/2)+$(document).scrollTop());
	if ($("#div-container").height() > $(document).height()){
		$(".div-preview-overlay").height($("#div-container").height());
	}else{
		$(".div-preview-overlay").height($(document).height());
	}
}
function preview_player_remove(){
	$("#div-preview-mov").remove();
	$(".div-preview-overlay").remove();
}
function preview_player(player_src, player_vars){
	$("body").prepend('<div id="div-preview-mov"></div>');
	$("#div-preview-mov").flash(
		{ 
          src: player_src,
          //width: 395,
          width: 660,
          //height: 295,
          height: 420,
          wmode: "transparent",
          flashvars: { playlistxml: player_vars }
        },
        { version: 7 }
	);
	$("body").prepend('<div class="div-preview-overlay"></div>');
	preview_player_arrange();
	$(".div-preview-overlay").click(function(){
		preview_player_remove();
	});
	return false;
}
function get_full_list(file, pdata, obj) {
	p_obj = $(obj).parent();
	$(p_obj).append('<div class="div-full-list-content"></div><img class="img-loader" src="' + burl + 'fileadmin/templates/dk.muvio/images/ajaxloader_white.gif" />');
	$(p_obj).find(".a-get-full-list-link").hide();
	$(p_obj).find(".div-full-list-content").hide();
	$.post(file, pdata,
		function(data){
			$(p_obj).find(".div-full-list-content").html(data);
			$(p_obj).find(".div-full-list-content").slideDown("slow", function(){
				$.scrollTo($(p_obj).find(".div-full-list-content"), "slow");
			});
			$.scrollTo($(p_obj).find(".div-full-list-content"), "slow");
			$(p_obj).find(".img-loader").remove();
	}, "html");
}
var cat_dd_hide = new Array();
function hide_cat_dd(popup){
	if(cat_dd_hide[popup] == 1){
		$("div#"+popup).animate({opacity:"hide"},"fast");
	}
}
$(function() {
	$("li.menulayerone_item_dropdown").hover(function() {
		var popup = $(this).attr("popup");
		cat_dd_hide[popup] = 0;
		//var apos = $("li.menulayerone_item_dropdown").offset();
		var apos = $(this).offset();
		
		var tpos = $("ul.menulayerone").offset();
		//var cat_dd_right = Math.round((974-(apos.left-tpos.left))-$("div#"+popup).outerWidth());
		//var cat_dd_right = apos.left-tpos.left;
		var cat_dd_right = apos.left-tpos.left+1;
		if($.browser.msie && $.browser.version.substr(0,1) == 6){
			cat_dd_right = cat_dd_right+5;
		}
		if (cat_dd_right < 1) { cat_dd_right = 1; }
		//$("div#"+popup).css("right",cat_dd_right);
		$("div#"+popup).css("left",cat_dd_right);
		/*
		var cat_dd_height = $("div#div-dd-cat").outerHeight();
		if($.browser.msie && $.browser.version.substr(0,1) == 6){
			if (cat_dd_height < 285) { $("div#div-dd-cat").height(285); }
		}else{
			if (cat_dd_height < 283) { $("div#div-dd-cat").height(283); }
		}
		*/
		$("div#"+popup).animate({opacity:"show"},"fast");
		return false;
	}, function() {
		cat_dd_hide[$(this).attr("popup")]=1;
		setTimeout("hide_cat_dd('"+$(this).attr("popup")+"')", 300);
	});
	$("div.div-menu-dropdown").hover(
		function() {
			cat_dd_hide[$(this).attr("id")]=0;
		},
		function() {
			cat_dd_hide[$(this).attr("id")]=1;
			setTimeout("hide_cat_dd('"+$(this).attr("id")+"')", 300);
		}
	);
});
function popup_arrange(){
	//$(".div-preview-overlay").css("z-index", hovercount++);
	//$("#div-preview-mov").css("z-index", hovercount++);
	//$("#div-popup").css("z-index", hovercount++);
	$("#div-popup").css("left", ($(document).width()-$("#div-popup").find("iframe").width())/2);
	$("#div-popup").css("top", (($(window).height()-$("#div-popup").find("iframe").height())/2)+$(document).scrollTop());
	if ($("#div-container").height() > $(document).height()){
		$(".div-preview-overlay").height($("#div-container").height());
	}else{
		$(".div-preview-overlay").height($(document).height());
	}
}
function popup_remove(){
	$("#div-popup").remove();
	$(".div-preview-overlay").remove();
}
function popup_win(popup_src, popup_width, popup_height){
	$("body").prepend('<div id="div-popup"></div>');
	//$("#div-popup").html('<div style="text-align: right;margin-right: 9px;"><a href="javascript:popup_remove();"><img src="/fileadmin/templates/dk.muvio/images/luk_popup.gif" border="0" /></a></div><iframe src="'+popup_src+'" width="'+popup_width+'" height="'+popup_height+'" frameborder="0" scrolling="no" allowTransparency="true"></iframe>');
	$("#div-popup").html('<iframe src="'+popup_src+'" width="'+popup_width+'" height="'+popup_height+'" frameborder="0" scrolling="no" allowTransparency="true"></iframe>');
	$("body").prepend('<div class="div-preview-overlay"></div>');
	popup_arrange();
	$(".div-preview-overlay").click(function(){
		popup_remove();
	});
	return false;
}

function popup_sp_win(popup_src, popup_width, popup_height){
	$("body").prepend('<div id="div-popup"></div>');
	//$("#div-popup").html('<div style="text-align: right;margin-right: 9px;"><a href="javascript:popup_remove();"><img src="/fileadmin/templates/dk.muvio/images/luk_popup.gif" border="0" /></a></div><iframe src="'+popup_src+'" width="'+popup_width+'" height="'+popup_height+'" frameborder="0" scrolling="no" allowTransparency="true"></iframe>');
	$("#div-popup").html('<div class="div-sp-popup-closelink"><a href="#" onclick="popup_remove(); return false;">Luk <strong>X</strong></a></div><iframe src="'+popup_src+'" width="'+popup_width+'" height="'+popup_height+'" frameborder="0" scrolling="no" allowTransparency="true"></iframe>');
	$("body").prepend('<div class="div-preview-overlay"></div>');
	popup_arrange();
	$(".div-preview-overlay").click(function(){
		popup_remove();
	});
	return false;
}

function buy_from_player(productid,sale){
	//$.post('/index.php?eID=minibasket',{request: 'add', productId:productid, productPrice:price, productTitle:title}, function(data) {
	if(sale == 1) {
		$.post(burl + 'index.php?eID=minibasket',{request: 'add', productId:productid + '_sale'}, function(data) {
			$('#div-minibasket-content').html(data);
		});
	}
	else {
		$.post(burl + 'index.php?eID=minibasket',{request: 'add', productId:productid + '_rent'}, function(data) {
			$('#div-minibasket-content').html(data);
		});
	}
}