﻿jQuery(function ($) {
    $(document).ready(function () {

        $("#MainMenu li a").wrapInner("<span></span>");


        //Fix click on images / lead
        var ListItems = ".pageList li";

        $(ListItems).click(function () {
            var href = $(this).find('a').attr('href');
            if (href == null)
                href = $(this + " h3").find('a').attr('href');
            if (href != null) window.location = href;
        });

        $('.product_page .holdbg .button').click(function () {
            $('.leadHolder').hide();
            $('.bodyHolder').show();
            $('.productpage-tabs').show();

            var productheight = $('.productpane .bodyHolder').height();
            if (productheight > 0) {
                productheight = productheight + 100;
                $('.product_page .inner').height(productheight);
            }

            //            alert("height:" + productheight);
        });



        $('#buttonKundeservice').click(function () {

            var top = $('#sidebarBestilling').height() + 200;
            //            $("html").animate(top, 'fast');
            $("html").animate({ scrollTop: top }, 'fast');

            //            $('#sidebarBestilling').hide();  
            //            $('#sidebarKundeservice').show();  
            //            
            //            $('#buttonBestilling').removeClass("active_tab");
            //            $('#buttonKundeservice').addClass("active_tab");       
        });
        //   
        $('#buttonPrivat').click(function () {

            $('#sidebarBestilling').hide();
            $('#sidebarPrivat').show();
            $('#sidebarBedrift').hide();

            $('.support a').removeClass("active_tab");
            $('#buttonPrivat').addClass("active_tab");
        });

        $('#buttonBedrift').click(function () {

            $('#sidebarBestilling').hide();
            $('#sidebarPrivat').hide();
            $('#sidebarBedrift').show();

            $('.support a').removeClass("active_tab");
            $('#buttonBedrift').addClass("active_tab");
        });

        $('#buttonBestilling').click(function () {

            $('#sidebarBestilling').show();
            $('#sidebarPrivat').hide();
            $('#sidebarBedrift').hide();

            $('.support a').removeClass("active_tab");
            $('#buttonBestilling').addClass("active_tab");
        });

        $('.ContactImage').cycle({
            fx: 'fade',
            speed: 2500,
            timeout: 8000
        });

        $('.QuickSearchField').Watermark();
        $('#id_matrix .txtbox').Watermark();
        $('#id_matrix .txtarea').Watermark();

//        Watermark('.txtbox');

        $("ul.YouTubes").ytplaylist({ addThumbs: true, autoPlay: false, playerWidth: '524', playerHeight: '320' });
        //        $('ul.YouTubes li').fadeTo('fast', 0.5);
        //        $('.currentvideo').fadeTo('fast', 1);
        //        $('ul.YouTubes li a').click(function () {
        //            $('ul.YouTubes li').fadeTo('fast', 0.5, function () {
        //                $('.currentvideo').fadeTo('fast', 1);
        //            });
        //        });


        //Make order form height equal to left column
        var leftElement = $('.product_page .main');
        var rightElement = $('.col3 .main');

        if (leftElement != null && rightElement != null) {
            if ((leftElement.height() > rightElement.height()) && leftElement.height() < 600) {
                if ($.browser.msie && $.browser.version == 6.0) { $(rightElement).css({ 'height': leftElement.height() }); }
                else $(rightElement).css({ 'min-height': leftElement.height() });
            };
        };

    });
});

(function ($) {
    $.fn.Watermark = function (options) {     

        return this.each(function () {
            var watermarkText = $(this).attr('title');

            $(this).val(watermarkText);
            $(this).addClass('watermark');
            
            $(this).focus(function () {                    
                if ($(this).val() == watermarkText)
                {
                    $(this).val('');
                    $(this).removeClass('watermark');
                }
            });

            $(this).blur(function () {
                if ($(this).val() == '')
                {
                    $(this).val(watermarkText);
                    $(this).addClass('watermark');
                }
            });
        });
    }
})(jQuery);

//function Watermark(watermarkThis) {

//    var watermarkText = "";

//    $(watermarkThis).load(function () {
//        watermarkText = $(this).attr('title');
//    });

//    $(watermarkThis).val(watermarkText);
//    $(watermarkThis).focusin(function () {
//        
//        if ($(this).val() == watermarkText)
//            $(this).val("");
//    });

//    $(watermarkThis).focusout(function () {
//        watermarkText = $(this).attr('title')
//        if ($(this).val() == "")
//            $(this).val(watermarkText);
//    });

//};
