var hovercount = 3000;
$(document).ready(function(){

	var q = $.parseQuery();
	var currentTime = new Date()
	q['ts'] = currentTime.getTime();
	//$.get(burl + 'index.php?id=190', q, function(data) {
	$.get(burl + 'loginform/', q, function(data) {
		$('#div-toplogin').html(data);
	});

	if($(".div-minibasket")) {
		$.post(burl + 'index.php?eID=minibasket',{} , function(data) {
			$('#div-minibasket-content').html(data);
		});
	}

	if($(".div-bannerad")) {
		$.post(burl + 'banner-reklame/',{} , function(data) {
			$('.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");
	});
	
	$("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>');
});

$(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);
		});
	}
}

function popup_paymentredirect(url){
	$("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 style="z-index:50200;width:215px;height:225px;background-image:url(' + burl + 'fileadmin/templates/dk.muvio.lidtmere/images/redirect-popupbg1.gif);text-align:center;"><div style="padding: 50px 5px 5px 5px;color:#ffffff;font-weight: bold;font-size:14px;width:205px; vertical-align: middle;">Vi videresender dig til vores filmpartner, MUVIO for at gennemføre transaktionen.<br/><br/>God fornøjelse LIDTmere.dk</div></div>');
	$("body").prepend('<div class="div-preview-overlay"></div>');

	//$(".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()-215)/2);
	$("#div-popup").css("top", (($(window).height()-225)/2)+$(document).scrollTop());
	if ($("#div-container").height() > $(document).height()){
		$(".div-preview-overlay").height($("#div-container").height());
	}else{
		$(".div-preview-overlay").height($(document).height());
	}

	setTimeout('document.location.href="' + url + '"', 5000);
	return false;
}


