/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />



//finn forhandler
function hiLite(imgName, imgObjName) {
    if (document.images) {
        document.images[imgName].src = eval(imgObjName + ".src");
    }
}

if (document.images) {
    image00 = new Image(); image00.src = "/images/map/norge.gif";
    image01 = new Image(); image01.src = "/images/map/ostfold.gif";
    image02 = new Image(); image02.src = "/images/map/akershus.gif";
    image03 = new Image(); image03.src = "/images/map/oslo.gif";
    image04 = new Image(); image04.src = "/images/map/hedmark.gif";
    image05 = new Image(); image05.src = "/images/map/oppland.gif";
    image06 = new Image(); image06.src = "/images/map/buskerud.gif";
    image07 = new Image(); image07.src = "/images/map/vestfold.gif";
    image08 = new Image(); image08.src = "/images/map/telemark.gif";
    image09 = new Image(); image09.src = "/images/map/austagder.gif";
    image10 = new Image(); image10.src = "/images/map/vestagder.gif";
    image11 = new Image(); image11.src = "/images/map/rogaland.gif";
    image12 = new Image(); image12.src = "/images/map/hordaland.gif";
    image14 = new Image(); image14.src = "/images/map/sognogfjordane.gif";
    image15 = new Image(); image15.src = "/images/map/moreogromsdal.gif";
    image16 = new Image(); image16.src = "/images/map/sortrondelag.gif";
    image17 = new Image(); image17.src = "/images/map/nordtrondelag.gif";
    image18 = new Image(); image18.src = "/images/map/nordland.gif";
    image19 = new Image(); image19.src = "/images/map/troms.gif";
    image20 = new Image(); image20.src = "/images/map/finnmark.gif";
}



function ajaxSuccess(request) {
/*
    var imgArray = null;
    var response = request.toString();
    try {
        imgArray = new Asset.images(['' + response + ''], {
            onComplete: function() {
                top.document.getElementById('hoverimage').src = imgArray[0].src;
            }
        });

    } catch (a) {
        return;
    }
    */
}


var windowOffsetTop = 0;
var windowOffsetLeft = 0;

var imgHeight = 230;
var imgWidth = 300;

this.screenshotPreview = function () {
    /* CONFIG */

    xOffset = 10;
    yOffset = 30;

    //var offset = $(this).offset();

    //var relativeX = (e.pageX - offset.left);
    //var relativeY = (e.pageY - offset.top);

    //alert(relativeY);


    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result

    /* END CONFIG */
    $("a.screenshot").hover(function (e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='screenshot'><img src='" + this.rel + "' alt='url preview' />" + c + "</p>");



        //alert($("#frame").height());

        if ((e.pageY - +imgHeight) > $("#frame").height()) {
            windowOffsetTop = imgHeight;
        }
        else {
            //windowOffsetTop = -40;
			windowOffsetTop = imgHeight;
        }

        if ((e.pageX + imgWidth) > $("#frame").width()) {
            windowOffsetLeft = imgWidth;
        }
        else {
            windowOffsetLeft = 0;
        }

        $("#screenshot")
			.css("top", (e.pageY - xOffset - windowOffsetTop) + "px")
			.css("left", (e.pageX + yOffset - windowOffsetLeft) + "px")
			.fadeIn("fast");
    },
	function () {
	    this.title = this.t;
	    $("#screenshot").remove();
	});
	$("a.screenshot").mousemove(function (e) {
        // if only one row is showing
        if (400 > $("#frame").height()) {
            windowOffsetTop = -40;
        }
        // if at the bottom of the page
        else if ((e.pageY + imgHeight) > $("#frame").height()) {
            windowOffsetTop = imgHeight;
        }
        else {
            windowOffsetTop = -40;
        }

        if ((e.pageX + imgWidth) > $("#frame").width()) {
            windowOffsetLeft = imgWidth;
        }
        else {
            windowOffsetLeft = 0;
        }

        $("#screenshot")
			.css("top", (e.pageY - xOffset - windowOffsetTop) + "px")
			.css("left", (e.pageX + yOffset - windowOffsetLeft) + "px");
    });
};

function ShowPopup() {
    try {
        //var imgLoading = 'images/loading.gif';
        //top.document.getElementById('hoverimage').src = imgLoading;


        //showable = "no";
        //var hp = top.document.getElementById('hoverpopup');
        //hp.style.top = y;
        //hp.style.left = x;
        //hp.style.display = '';

    } catch (a) {
        return
    }
}

function HidePopup() {
    try {
        var hp = top.document.getElementById('hoverpopup');
        var ot = top.document.getElementById('hoverimage');
        if (permanent == "no") {
            showable = "no";
            hp.style.display = 'none';
            ot.src = '';
        }
    } catch (a) {
        return;
    }
}


function zoomIn() {
    try {

        /*
        showable = "yes";
        var stringdescr = "";
        var stringfooter = "";
        var contHeight;

            contHeight = getSize("y");

            x = $(obj).offsetLeft + 320;
        y = getLoc(event) + 120;
        if ((y + 150) > contHeight) {
        y = y - 260;
        x = x + 10;
        }

            stringdescr = '' + imgname + ' ';
        if (dimention != '') {
        stringfooter = stringfooter + '<b>§Dimensjon#Dimention§: </b>' + dimention + ' px&#160;&#160;';
        }
        if (strlse != '') {
        var strlse2 = strlse / 1000;
        strlse2 = strlse2.toFixed(2);
        stringfooter = stringfooter + '<b>§Filstørrelse#File size§: </b>' + strlse2 + ' kb';
        }

            var c = top.document.getElementById('headertext');
        top.document.getElementById('headertext').innerHTML = stringdescr + '&#160';
        top.document.getElementById('footertext').innerHTML = stringfooter;
        */

        new Ajax("show_image.aspx", {
            method: "post",
            data: "",
            onComplete: ajaxSuccess
        }).request();

        //if (showable == "yes") {
            //ShowPopup();
        //}

        alert("yes");

    } catch (a) {

    alert(a.description);
    
        return;
    }

}

var displayImageActive = false;

function displayImage(imgSrc) {

    var htmlContent = '<img src="/upload_images/' + imgSrc + '" width="959px" alt=""/>';

    htmlContent = htmlContent + '<img id="exit_button" class="clickable" style="position:absolute;bottom:0px;left:0px;z-index:1500;" src="/images/design/close_button.png" alt="lukk"/>';

    document.getElementById('large_img').innerHTML = htmlContent;
    $('#middle_content').css("paddingBottom", "0px");
    $('#large_img_outer').css("display", "block");
    $('#large_img_exit').css("display", "block");
    $('#large_img_exit_back').css("display", "block"); 
}

$(document).ready(function() {

    screenshotPreview();

    $('#neste', this).bind("click", function() {

    if ($("#currentPage").html() != $("#totalPages").html() && !$(".catalog_search_result").is(':animated')) {
        $(".catalog_search_result").css({ "top": (parseInt($('.catalog_search_result').css('top'))) + -70 }, { duration: 500 });

            
            $("#currentPage").html(parseInt($("#currentPage").html()) + 1);
        }
    });

    $('#forrige', this).bind("click", function() {

        if (parseInt($("#currentPage").html()) != 1 && !$(".catalog_search_result").is(':animated')) {
            $(".catalog_search_result").css({ "top": (parseInt($('.catalog_search_result').css('top'))) + 70 }, { duration: 500 });
            
            $("#currentPage").html(parseInt($("#currentPage").html()) + -1);
        }

    });

    $('#large_img_exit', this).bind("click", function() {

        $('#middle_content').css("paddingBottom", "0px");
        $('#large_img_outer').css("display", "none");
        $('#large_img_exit').css("display", "none");
        $('#large_img_exit_back').css("display", "none");
    });

    $('#exit_button', this).bind("click", function() {

        $('#middle_content').css("paddingBottom", "0px");
        $('#large_img_outer').css("display", "none");
        $('#large_img_exit').css("display", "none");
        $('#large_img_exit_back').css("display", "none");
    });


    $(".forhandler_fylke", this).bind("click", function() {
        //alert($(this).parent().parent().find(".getDealers").hasClass("getDealers"));
        //$(".getDealers").animate({ "display": "block" }, { duration: 500 });

        //alert($(this).parent().parent().parent().find(".getDealers").html());


        if ($(this).parent().parent().parent().find(".getDealers").css("display") == "none") {
            $("#showDealer").html($(this).parent().parent().parent().find(".getDealers").html());
        }
        else {
            $(this).parent().parent().parent().find(".getDealers").hide(300);
        }

    });






    var fadeTime = 500;

    $('.doc2_info_content_loading_first').fadeOut(fadeTime, function() {
        $('.doc2_info_content_loading_first').css('display', 'none');
    });

    $('.doc2_info_inactive').parent().find('.doc2_info_content').slideToggle(1);

    $('.doc2_info_header', this).bind("click", function() {

        var thisObject = this;

        if (!$(thisObject).hasClass("isAni")) {

            var text_div = $(thisObject).parent().find('.doc2_info_content');
            /*var this_img = $(thisObject).find('#div_eq_' + thisObject.id);*/

            if ($(text_div).is(':hidden')) {

                if ($('.doc2_info_active').hasClass('doc2_info_active')) {

                    var open_div = $('.doc2_info_active');

                    $(open_div).addClass("isAni");
                    $(open_div).removeClass("doc2_info_active");

                    $(open_div).parent().find('.doc2_info_content').slideToggle((open_div).parent().find('.doc2_info_content').height(), function() {
                        $(open_div).removeClass("isAni");
                        $(thisObject).removeClass("doc2_info_inactive");

                    });

                    $(open_div).parent().find('.doc2_info_content_loading').css('display', 'block');
                    $(open_div).parent().find('.doc2_info_content_loading').fadeIn();

                    $(thisObject).addClass("isAni");

                    $(text_div).slideToggle($(text_div).height(), function() {
                        $(thisObject).removeClass("isAni");
                        $(thisObject).addClass("doc2_info_active");
                    });

                    $(thisObject).parent().find('.doc2_info_content_loading').fadeOut(fadeTime, function() {
                        $(thisObject).parent().find('.doc2_info_content_loading').css('display', 'none');
                    });


                }
                else {
                    $(thisObject).addClass("isAni");
                    $(thisObject).removeClass("doc2_info_inactive");

                    $(text_div).slideToggle($(text_div).height(), function() {
                        $(thisObject).addClass("doc2_info_active");
                        $(thisObject).removeClass("isAni");
                    });

                    $(thisObject).parent().find('.doc2_info_content_loading').fadeOut(fadeTime, function() {
                        $(thisObject).parent().find('.doc2_info_content_loading').css('display', 'none');
                    });
                }


                //$("img", this).attr("src", "/images/design/sitemap_up.png");



                //$(text_div).removeClass("openThisLevel2_inactive");
                //$(text_div).addClass("openThisLevel2_active");
            }
            else {

                //$("img", this).attr("src", "/images/design/sitemap_down.png");

                $(thisObject).removeClass("doc2_info_active");
                $(thisObject).addClass("doc2_info_inactive");
                $(text_div).slideToggle($(text_div).height(), function() { $(thisObject).removeClass("isAni"); });

                $(thisObject).parent().find('.doc2_info_content_loading').fadeIn();

                //$(text_div).removeClass("openThisLevel2_active");
                //$(text_div).addClass("openThisLevel2_inactive");
            }

            //$(text_div).slideToggle($(text_div).height(), function() { $(thisObject).removeClass("isAni"); });

        } // end if (!$(thisObject).hasClass("isAni")) {
    });

});

/* Google Maps integration -------------------------------------------------------------------------------------- */
function AttachGMap(address, infobox, id, form_id) {

	var geocoder = null;
	var map = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(id));

		// Add marker for store address
		var geocoder = new GClientGeocoder();
		var point = geocoder.getLatLng(address, function(point) {

			if (!point) {
				//alert(address + " not found");
				// address not found, make maps invisible
				$("#" + id).css("background", "#fff");

			} else {
				var marker0 = new GMarker(point);
				marker0.title = "";
				map.addOverlay(marker0);
				map.setCenter(point, 13);
				GEvent.addListener(marker0, "click", function() {
					// submit to maps.google.no
					document.getElementById(form_id).submit();
				});
			}

			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
		});
	}

	// hide copyrightinfo on the bottom. I did this because it was too big and went outside designated area.
	//$("#" + id + " .gmnoprint,#" + id + " > div:last").css("display", "none");
}

