﻿var MoviePlay=false;

/*
function slideshow(DivID)
{

   if (!MoviePlay)
   {
        var $active = $('#' + DivID + ' DIV.Active');

        if ( $active.length == 0 ) $active = $('#' + DivID + ' DIV:last');

        var $next =  $active.next().length ? $active.next()
            : $('#' + DivID + ' DIV:first');

        $active.addClass('LastActive');

        $next.css({opacity: 0.0})
            .addClass('Active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('Active LastActive');
            });
        }
    }

$(document).ready(function() {

    $(".ShowProducts").click(function() {
        $(".ProductListSmall").show(500);
        $(".ShowProducts").hide();
        $(".HideProducts").show();
        $(".ProductList .ProductsSmallBody").css('padding-top', '10px');
    });

    $(".HideProducts").click(function() {
        $(".ProductListSmall").hide(500);
        $(".HideProducts").hide();
        $(".ShowProducts").show();
        $(".ProductList .ProductsSmallBody").css('padding-top', '0px');
    });

});

*/


/* fileinputs */

var FileInputManager = {
};

FileInputManager.Init = function() {

    $(".UploadField").filestyle({
        image: "/Templates/Images/folder.png",
        imageheight: 22,
        imagewidth: 30,
        width: 128
    });

};

    $(document).ready(function() {


        /* Movie */


        $(".MovieLink").click(function(e) {

            //Cancel the link behavior
            e.preventDefault();
            MoviePlay = true;
            $('#FlashWin').html(myFlash);

            //Get the div
            var id = '#MovieWindow';

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set heigth and width to mask to fill up the whole screen
            $('#Mask').css({ 'width': maskWidth, 'height': maskHeight });

            //transition effect		
            $('#Mask').fadeIn(200);
            $('#Mask').fadeTo("fast", 0.5);

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window position
            //	$(id).css('top',  winH/2-$(id).height()/2);
            $(id).css('top', 120);
            $(id).css('left', winW / 2 - $(id).width() / 2);

            //transition effect
            $(id).fadeIn(100);


            //if close button is clicked
            $('.Window .Close').click(function(e) {
                //Cancel the link behavior
                e.preventDefault();

                $('#Mask').hide();
                $('.Window').hide();

                MoviePlay = false;
                $("#FlashWin").html('');
            });

            //if mask is clicked
            /*	$('#Mask').click(function () {
            $(this).hide();
            $('.Window').hide();
            });			
            */
        });

        //TooltipManager.Init();
    });

$(window).resize(function() { 

	var id = '#MovieWindow';

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#Mask').css({'width':maskWidth,'height':maskHeight});

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
          
	//Set the popup window to center
	$(id).css('top',  120);
	$(id).css('left', winW/2-$(id).width()/2);

});

/* ToolTip */

var TooltipManager = {
    "ProductData": undefined,
    "ProductOrderListData":undefined,
    "ItemsLeft" : 5
};

TooltipManager.Init = function() {

    var xOffset = -60;
    var yOffset = -191;

    $(".ProdLink").mouseover(function() {

        this.Tilf = this.href.split("#");

        this.Count = parseInt(this.Tilf[1]);
        this.ProductName = TooltipManager.ProductData[this.Count][0];
        this.ProductText = TooltipManager.ProductData[this.Count][1];
        this.ProductImage = TooltipManager.ProductData[this.Count][2];
        this.ProductLink = TooltipManager.ProductData[this.Count][3];

        //xOffset = -60;
        this.Bg = "TooltipLeft";

        if (this.Count >= TooltipManager.ItemsLeft) {
            xOffset = -328;
            this.Bg = "TooltipRight";
        } else {
            xOffset = -60;
            this.Bg = "TooltipLeft";
        }


        var Content = '<img src="' + this.ProductImage + '" width="265" height="172" class="TooltipImage" /><div class="TooltipInfo"><p class="TooltipHeadline">' + this.ProductName + '</p><p class="TooltipText">' + this.ProductText + '</p></div>';
        var TooltipStr = "<div id='Tooltip' class='" + this.Bg + "'><div class='TooltipInner'>" + Content + "</div><a href='" + this.ProductLink + "' class='ToProductLink'></a></div>";

        $("body").append(TooltipStr);

        var posX, posY;

        var posX = $(this).offset().left;
        var posY = $(this).offset().top;

        $("#Tooltip")
        .css("top", ((posY + yOffset) + "px"))
        .css("left", ((posX + xOffset) + "px"))
        .show();

    });

    $(".ProdLink").mouseout(function() {
        $("#Tooltip").remove();
    });


};

/* TooltipContact */

var TooltipContactManager = {
};

TooltipContactManager.Init = function() {

    var xOffset = [-96, -96, -390, -390];
    var yOffset = 300;



    $(".ContactInfoPopupLink").mouseover(function() {

        this.Tilf = this.href.split("#");

        this.Count = parseInt(this.Tilf[1]);

        this.Type = (this.Count-1) % 4;

        var posX, posY;

        var posX = $(this).offset().left - $(".ContactList").offset().left;
        var posY = $(this).offset().top - $(".ContactList").offset().top; ;


        //alert(posX + ":" + posY + ":" + this.Type);

        $(".ContactInfoPopup" + this.Count)
        .css("top", ((posY + yOffset) + "px"))
        .css("left", ((posX + xOffset[this.Type]) + "px"))
        .show();

    });

    $(".ContactInfoPopupLink").mouseout(function() {
        $(".ContactInfoPopup" + this.Count).hide();
    });


};

function writeEmail(email, href) {    
    site = '@kakservice.se';
    document.write('<a href="' + href + '">' + email + site + '</a>'  );    
}