﻿/// <reference path="jquery-1.5.1-vsdoc.js" />
var activeTab = 'cntImages';
var firstVideoUrl = '';



jQuery(function ($) {




    function sortNumber(a, b) {
        return a - b;
    }

    function maxHeight() {
        var heights = new Array();
        $('.campaignBox').each(function () {
            var hgt = $(this).css('height');

            $(this).css('height', 'auto');
            var h = $(this).height();

            heights.push(h);
            heights = heights.sort(sortNumber).reverse();
            var newH = heights[0]
            if (newH > 250) newH = 250;
            $(this).css('height', newH);

        });
    }

    function scrollToGroup() {

        var CurrentGroupNo = $("#hidCurrentGroupNo").val();
        if (CurrentGroupNo != null && CurrentGroupNo != '')
            $("#groupsBox").scrollTo("#group" + CurrentGroupNo);
    }


    function setGroupHeight() {
        var maxHgt = 3020;

        var offset = 300;
        var hgt = $(window).height() - offset;
        hgt = $("#main").height() - offset;
        if (hgt > maxHgt) {
            hgt = maxHgt
            $("#selectGroup #groupsBox").css('overflow', 'visible');
            $("#selectGroup .center-content").css('padding-left', 40);
        }
        else {
            scrollToGroup();
        }


        $("#selectGroup .center-content").css('height', hgt);
        $("#selectGroup #groupsBox").css('height', hgt - 20);

    }

    $(document).ready(function () {

        setGroupHeight();



        /* Menu */
        
        $("ul.down-list").each(function()
        {
            $("li:last",this).addClass("nobg");
        });



        $(".topMenuItem").hover(
    function () {
        $("ul.down-list").slideUp(200);
        $("ul.down-list", this).slideDown(300);

    },
    function () {
        $("ul.down-list").slideUp(200);
    }
);


        $('<tr class="tillbehorHeader"><td colspan="12">&nbsp;</td></tr>').insertBefore($('.tillbehor'));


        $("#btnFullScreen").click(function () {
            $("body").toggleClass("fullScreen");
        });


        $("#morePriceInfoLink").click(function () {

            $("#morePriceInfo").toggle();
        });

        $("#morePriceInfo").click(function () { $("#morePriceInfo").hide() })

        maxHeight();
        $("a.whiteBtn").prepend("<span></span>");
        $("a.whiteBtn").hover(
	  function () {
	      $(this).addClass('whiteBtnover');
	  },
	  function () {
	      $(this).removeClass('whiteBtnover');
	  }
	);
    })

    $(window).resize(maxHeight);


    $(".down-list li").hover(
	  function () {
	      $(this).addClass('over');
	  },
	  function () {
	      $(this).removeClass('over');
	  }
	);

    $('#topMenu .topMenuItem').each(function (i) {
        var url = $("a", this).attr("href");
        $(this).attr("title", url);
        $(this).click(function () {


            if (url != null)
                location.href = url;
        })

    });

    $("#topMenu .menu-first a").css("visibility", "hidden");




    $(document).ready(function () {

        $("#loader").hide();

        var firstReRenter = $('#topMenu .reRenter, #leftMenu .reRenter').first();
        $('<li class="reRenterSeparator">ÅTERUTHYRARE</li>').insertBefore(firstReRenter);

        var firstReRenterLeftMenu = $('#leftMenu .reRenter').first();
        $('<li class="reRenterSeparator">ÅTERUTHYRARE</li>').insertBefore(firstReRenterLeftMenu);


        $("#top").click(function () { location.href = '/'; });

        //$('.down-list').width($('.topMenuItem div').width() - 22);
        //        $('#topMenuShowTrigger').hover(
        //	  function () {
        //	      $('.topMenuItem', this).addClass('slide-down');
        //	      $('#topMenuContentBg').slideDown(100);
        //	      $('.down-list').slideDown(100);
        //	      setTimeout("$('#topMenuContentBg').slideUp(100);$('.down-list').slideUp(100);", 10000);
        //	  },
        //	  function () {

        //	  }
        //	);


        $('#topMenuContentBg #imgClose').click(
	  function () {
	      $('#topMenuContentBg').slideUp(100);
	  });

        $('#top', '#mnuClose').hover(

	  function () {
	      obj = this;

	      $('.down-list').slideUp(100, function () { $('.topMenuItem', obj).removeClass('slide-down'); });
	      $('#topMenuContentBg').slideUp(100);
	  }
	);

        $('#topMenuContentBg').mouseleave(

	  function () {
	      obj = this;

	      $('.down-list').slideUp(100, function () { $('.topMenuItem', obj).removeClass('slide-down'); });
	      $('#topMenuContentBg').slideUp(100);
	  }
	);

    });




    $(document).ready(function (e) {
        $('.tabContent').each(function (i) {
            $(this).hide();
        });
        $('#' + activeTab).hide();
        $('#' + activeTab).fadeIn("slow");


        $('.tab').click(function (e) {

            $('.tab').each(function (i) {
                $(this).removeClass('current');
            });
            var showLayer;
            switch (this.id) {
                case 'tabImgs': showLayer = "cntImages";
                    break;
                case 'tabDiagram': showLayer = "cntDiagram";
                    break;
                case 'tabVideo':
                    showLayer = "cntVideo";
                    showVideo('', firstVideoUrl);
                    break;
                default: showLayer = "cntFiles";
            }

            $('.tabContent').each(function (i) {
                $(this).hide();
            });

            $('#' + showLayer).fadeIn("slow");

            activeTab = showLayer;
            $(this).addClass("current");
        });

    });

});

$(document).ready(function () {
	$(".tblProductGroup tr").mouseover(function () { $(this).addClass("over"); }).mouseout(function () { $(this).removeClass("over"); });
});


$(document).ready(function () {

//    $(function () {
//        $(".tblProductGroup").selectable({
//            filter: 'td.compare',
//            stop: function (event, ui) {

//                var result = $("#select-result").empty();
//                $(".ui-selected", this).each(function () {
//                    var rowId = this.id;
//                    result.append((rowId) + ",");
//                });
//            }
//        });
//    });

	$(".tblProductGroup tr td").click(function (e) {
		var a = $(this).find("a").attr("href");
		if (a != null)
			location.href = a;
	});

});

var CurrentImgIndex = 0 ;

$(document).ready(function () {

    var firstImageSrc = $('#imgProductPrev').attr('src');


    $("#imgProductPrev").click(function (e) {

  

        CurrentImgIndex++;
        var img = document.getElementById('img' + CurrentImgIndex);
        if (img == null) {
            CurrentImgIndex = 0;
             $('#imgProductPrev').attr('src',firstImageSrc);
        }

        if (img != null) {

            $('#imgProductPrev').attr({
                src: img.src,
                title: img.title
            });

        }

    });
});

$(document).ready(function () {
	$(".alteringRowColor tr:even").css("background-color", "#cecece");
});
$(document).ready(function () {
	$(".tblProductGroup tr:even").css("background-color", "#cecece");
});
$(document).ready(function () {

    $('#cntImages .imgBox img, #cntDiagram .imgBox img').click(function (e) {

        CurrentImgIndex = $(this).attr('id').replace('img', '');

        $('#imgProductPrev').attr({
            src: this.src,
            title: this.title
        });

    });

});

function truncate(n) {
	return Math[n > 0 ? "floor" : "ceil"](n);
}


$(document).ready(function () {
    showCompareImg();




    $('.showCompare img').click(function (e) {



        $("#compareContainer").html('');

        $('#compareContainer').modal(
					{
					    containerCss: {
					        width: "90%", height: "520px"
					    }
					}
					);


        $("input[type=checkbox][:checked]").each(function () {
            if (this.checked && this.value != null && IsNumeric(this.value)) {


                $.ajax({ url: "/Templates/Pages/CompareProduct.aspx?ProductID=" + this.value, context: '.compareDiv', success: function (data) {
                    $("#compareContainer").append(data);

                    $(".alteringRowColor tr:even").css("background-color", "#cecece");
                    $(".closeImg").click(function (e) {
                        $(this).parent().css("display", "none");
                    });
                }


                });



            }
        });


    }
	);


    function IsNumeric(sText) {
        var ValidChars = "0123456789.";
        var IsNumber = true;
        var Char;


        for (i = 0; i < sText.length && IsNumber == true; i++) {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1) {
                IsNumber = false;
            }
        }
        return IsNumber;

    }



    function showCompareImg() {

        $('.compare').each(function (index) {




            if ($(this).children("input[type=checkbox]")[0].checked) {
                $(this).children("div").css('visibility', 'visible').css('display', 'inline');
            }
            else
                $(this).children("div").css('visibility', 'hidden').css('display', 'none');
        });





    }

    var allowShowCompareInfo = true;

    $('input[type=checkbox]').click(function (e) {


        var top = $(this).offset().top + window.screenY;
        var left = $(this).offset().left + window.screenX;
        top = truncate(top) - 132;
        left = truncate(left) - 125;
        var tx = 'left:' + left + 'px; top:' + top + 'px;';

        if ($('#' + (this).id + ':checked').val() !== undefined && allowShowCompareInfo) {
            $("#compareInfo").css("left", left);
            $("#compareInfo").css("top", top);
            $("#compareInfo").fadeIn(800);
        }


        showCompareImg();

    });

    $("#compareInfo").click(function () {
        allowShowCompareInfo = false;
        $("#compareInfo").fadeOut(200);
    });

    $(".tblProductGroup .iconColImg").hover(function () {
        $(this).css({ 'z-index': '10000' }); /*Add a higher z-index value so this image stays on top*/
        $(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
		    marginTop: '-5px', /* The next 4 lines will vertically align this image */
		    marginLeft: '-150px'

		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

    }, function () {
        $(this).css({ 'z-index': '0' }); /* Set z-index back to 0 */
        $(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
		    marginTop: '0', /* The next 4 lines will vertically align this image */
		    marginLeft: '5'
		}, 400);
    });


    //Visar personalbild
    $(".staffImage").hover(function () {
        $(this).css({ 'z-index': '10000' }); /*Add a higher z-index value so this image stays on top*/
        $(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
		    marginTop: '-100px', /* The next 4 lines will vertically align this image */
		    marginLeft: '-100px'

		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

    }, function () {
        $(this).css({ 'z-index': '0' }); /* Set z-index back to 0 */
        $(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
		    marginTop: '0', /* The next 4 lines will vertically align this image */
		    marginLeft: '0'
		}, 400);
    });


    $(".videoLink").click(function (e) {
        showVideo('', this.title);
        $('#productVideoContainer').modal({

            containerCss: {
                width: "460px", height: "320px"
            }

        });
        return false;
    });









    /*DEPÅ*/


    $(document).ready(function () {


        var firstImageDepotSrc = $('#imgPrev img').attr('src');
        
        $('.productDetails h2').dblclick(function (e) {
            window.open('/Templates/Pages/ProductText.aspx?ProductID=' + this.className, 'prod', 'width=600,height=600,resizable=yes');
        });



        $("#imgPrev img").click(function (e) {



            CurrentImgIndex++;
            var img = document.getElementById('img' + CurrentImgIndex);
            if (img == null) {
                CurrentImgIndex = 0;
                $('#imgPrev img').attr('src', firstImageSrc);
            }

            if (img != null) {

                $('#imgPrev img').attr({
                    src: img.src,
                    title: img.title
                });

            }

        });





        $('#smallImagesContainer .imageBoxSmall img').click(function (e) {
            CurrentImgIndex = $(this).attr('id').replace('img', '');

            $('#imgPrev img').attr({
                src: this.src,
                title: this.title
            });
            return false;
        });

    });


});






