﻿function featureBooksInit(elementGUID, elementBredde, featureBooksBredde) {
	var marginOgBorders = 2;	
	var featureBooksBredde = featureBooksBredde-marginOgBorders;

	$("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + " div").each(function (index) {
    $(this).css("margin-right",elementBredde-123+"px");
  });

$("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID ).css("width", antalPics * elementBredde + "px");
$("#featureBooks_" + elementGUID + " #featureBooksMask_" + elementGUID ).css("width", featureBooksBredde + "px");
$("#featureBooks_" + elementGUID + " #featureBooksBorder_" + elementGUID).css("width", featureBooksBredde + "px");
	checkButtonState(elementGUID);
	 
};

function featureBooksNext(elementGUID,checkButtonStateFunction,elementBredde) {
	if(featureBooksMoving) return;
	if ($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").position().left > 35 - (parseInt($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").width()) - parseInt($("#featureBooks_" + elementGUID + " #featureBooksMask_" + elementGUID + "").width()))) {
		featureBooksMoving=true;
		$("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").animate({ left: "-=" + elementBredde }, 1000, "swing", checkButtonStateFunction);
	}
};



function featureBooksPrev(elementGUID,checkButtonStateFunction,elementBredde) {
	if(featureBooksMoving) return;
	if ($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").position().left < 0) {
		featureBooksMoving=true;
		$("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").animate({ left: "+=" + elementBredde }, 1000, "swing", checkButtonStateFunction);
	}
};

function checkButtonState(elementGUID) {
	featureBooksMoving=false;
	var imgPrevPath;
	var imgNextPath;
	var path;
	if ($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").position().left < 0) {
		path = "/Frontend/Images/prev_knap_active.gif";
	}else{
		path = "/Frontend/Images/prev_knap_passive.gif";		
	}
if ($("#featureBooks_" + elementGUID + " #featureBooksPrevImg_" + elementGUID + "").attr("src") != path) $("#featureBooks_" + elementGUID + " #featureBooksPrevImg_" + elementGUID + "").attr("src", path);

if ($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").position().left > 35 - (parseInt($("#featureBooks_" + elementGUID + " #featureBooksContent_" + elementGUID + "").width()) - parseInt($("#featureBooks_" + elementGUID + " #featureBooksMask_" + elementGUID + "").width()))) {
		path="/Frontend/Images/next_knap_active.gif";
	}else{
		path="/Frontend/Images/next_knap_passive.gif";		
	}
if ($("#featureBooks_" + elementGUID + " #featureBooksNextImg_" + elementGUID + "").attr("src") != path) $("#featureBooks_" + elementGUID + " #featureBooksNextImg_" + elementGUID + "").attr("src", path);

};

/* QuickSearch */
function quickSearch() {
    var savedParam = $('#searchString').attr('value');
    var param = $('#searchString').attr('value').replace(/^\s+|\s+$/g, "");
    
    if (param.length > 1) {
    
        $.cookie('SearchQuery', param, { path: '/', expires: (new Date()) + (365 * 24 * 60 * 60 * 1000) });
    
        if (window.encodeURIComponent)
            param = encodeURIComponent(param);
        else
            param = escape(param);

        $('#searchString').attr('value', 'Søger. Vent venligst...');
        $('#searchString').attr('disabled', true);
        
        $('#dropDownSearchContent').load('/Ajax/GadsForlag.QuickSearchResult.ashx?SearchQuery=' + param + "&cultureScope=da-DK", function() {
            $('#searchString').attr('value', savedParam);
            $('#searchString').attr('disabled', false);
            showDropDown('Search', true);
        }); 
    }
}




/* BigPic */
$(document).ready(initBigPic);

function initBigPic() {
    if ($.browser.msie && parseInt($.browser.version) <= 6) return;
    $(window).resize(placerBigPic);
    $("#bigPicBackground").click(removeBigPic);
    $("#bigPic").click(removeBigPic);
    //$(window).scroll(placerBigPicBackground);
	$(window).resize(removeBigPic);
	$("#bigPic").load(bigPicLoaded);
}
function doBigPic(picUrl) {

    if ($.browser.msie && parseInt($.browser.version) <= 6) return;
	if($("#bigPic").attr("src") != picUrl) $("#bigPic").attr("src", picUrl);
	else $("#bigPic").css("display", "block");
	placerBigPicBackground();
}

function bigPicLoaded(){
    placerBigPic() 
	$("#bigPic").css("display","block");
}
function placerBigPic() {
    var heightMargin = ($(window).height() - $("#bigPic").height()) / 2;
    var widthMargin = ($(window).width() - $("#bigPic").width()) / 2;
    $("#bigPic").css("top", heightMargin + "px");
    $("#bigPic").css("left", widthMargin + "px");
}

function removeBigPic(){
	if($("#bigPicBackground").css("display")!="none"){
			$("#bigPicBackground").css("display","none");
			$("#bigPic").css("display","none");
	}
}

function placerBigPicBackground() {
    $("#bigPicBackground").css("display", "block");
    $("#bigPicBackground").css("left", $(window).scrollLeft() + "px");
}

/*FoldUd Start*/

function foldOutToggle(elementGUID) {
    $("#foldContent_" + elementGUID).slideToggle(500);
    var path = "/Frontend/Images/foldet_ud.gif";
    if (path == $("#foldPil_" + elementGUID + "").attr("src")) path = "/Frontend/Images/foldet_ind.gif";
    $("#foldPil_" + elementGUID + "").attr("src", path);
    return false;
}

function foldOutStart(elementGUID, hide) {
    if (!hide) return;
   var slideTime = 1;
    if ($.browser.msie && parseInt($.browser.version) <= 7) slideTime = 800;
    $("#foldContent_" + elementGUID).slideToggle(slideTime );
    var path = "/Frontend/Images/foldet_ud.gif";
    if (path == $("#foldPil_" + elementGUID + "").attr("src")) path = "/Frontend/Images/foldet_ind.gif";
    $("#foldPil_" + elementGUID + "").attr("src", path);
    return false;
}

/*FoldUd End*/

/*Issuu Start*/
function openIssuu(documentID, startSide) {
    $('#issuuContainer').css("display", "block");
    $('#issuuContainer').flash(
			{
			    width: 900,
			    height: 700,
			    swf: "http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf?mode=embed&amp;documentId=" + documentID + "&amp;layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml&amp;backgroundColor=F4F4F4&amp;pageNumber=" + startSide + ""
			}
		);
			placerIssuuContainer();
			$("#issuuBackground").click(closeIssuu);

			$(window).resize(placerIssuuContainer);
			$("#issuuBackground").css("display", "block");
			placerIssuuBackground();
}

function placerIssuuContainer() {
    var contentPosition = $('#content').position();
	$('#issuuContainer').css("left", contentPosition.left + 30 +"px");
}

function closeIssuu() {
    $('#issuuContainer').empty();
    $('#issuuContainer').css("display", "none");
    $("#issuuBackground").css("display", "none");
}

function placerIssuuBackground() {
    $("#issuuBackground").css("display", "block");
    $("#issuuBackground").css("left", $(window).scrollLeft() + "px");
}

/*Issuu End*/
