﻿/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version 2.1.2-pre
*/

(function ($) {

    /**
    * The bgiframe is chainable and applies the iframe hack to get
    * around zIndex issues in IE6. It will only apply itself in IE6
    * and adds a class to the iframe called 'bgiframe'. The iframe
    * is appeneded as the first child of the matched element(s)
    * with a tabIndex and zIndex of -1.
    *
    * By default the plugin will take borders, sized with pixel units,
    * into account. If a different unit is used for the border's width,
    * then you will need to use the top and left settings as explained below.
    *
    * NOTICE: This plugin has been reported to cause perfromance problems
    * when used on elements that change properties (like width, height and
    * opacity) a lot in IE6. Most of these problems have been caused by
    * the expressions used to calculate the elements width, height and
    * borders. Some have reported it is due to the opacity filter. All
    * these settings can be changed if needed as explained below.
    *
    * @example $('div').bgiframe();
    * @before <div><p>Paragraph</p></div>
    * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
    *
    * @param Map settings Optional settings to configure the iframe.
    * @option String|Number top The iframe must be offset to the top
    * by the width of the top border. This should be a negative
    * number representing the border-top-width. If a number is
    * is used here, pixels will be assumed. Otherwise, be sure
    * to specify a unit. An expression could also be used.
    * By default the value is "auto" which will use an expression
    * to get the border-top-width if it is in pixels.
    * @option String|Number left The iframe must be offset to the left
    * by the width of the left border. This should be a negative
    * number representing the border-left-width. If a number is
    * is used here, pixels will be assumed. Otherwise, be sure
    * to specify a unit. An expression could also be used.
    * By default the value is "auto" which will use an expression
    * to get the border-left-width if it is in pixels.
    * @option String|Number width This is the width of the iframe. If
    * a number is used here, pixels will be assume. Otherwise, be sure
    * to specify a unit. An experssion could also be used.
    * By default the value is "auto" which will use an experssion
    * to get the offsetWidth.
    * @option String|Number height This is the height of the iframe. If
    * a number is used here, pixels will be assume. Otherwise, be sure
    * to specify a unit. An experssion could also be used.
    * By default the value is "auto" which will use an experssion
    * to get the offsetHeight.
    * @option Boolean opacity This is a boolean representing whether or not
    * to use opacity. If set to true, the opacity of 0 is applied. If
    * set to false, the opacity filter is not applied. Default: true.
    * @option String src This setting is provided so that one could change
    * the src of the iframe to whatever they need.
    * Default: "javascript:false;"
    *
    * @name bgiframe
    * @type jQuery
    * @cat Plugins/bgiframe
    * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
    */
    $.fn.bgIframe = $.fn.bgiframe = function (s) {
        // This is only for IE6
        if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
            s = $.extend({
                top: 'auto', // auto == .currentStyle.borderTopWidth
                left: 'auto', // auto == .currentStyle.borderLeftWidth
                width: 'auto', // auto == offsetWidth
                height: 'auto', // auto == offsetHeight
                opacity: true,
                src: 'javascript:false;'
            }, s || {});
            var prop = function (n) { return n && n.constructor == Number ? n + 'px' : n; },
html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + s.src + '"' +
'style="display:block;position:absolute;z-index:-1;' +
(s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');' : '') +
'top:' + (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')' : prop(s.top)) + ';' +
'left:' + (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')' : prop(s.left)) + ';' +
'width:' + (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')' : prop(s.width)) + ';' +
'height:' + (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')' : prop(s.height)) + ';' +
'"/>';
            return this.each(function () {
                if ($('> iframe.bgiframe', this).length == 0)
                    this.insertBefore(document.createElement(html), this.firstChild);
            });
        }
        return this;
    };

})(jQuery);
/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

*
*  <ul id="news"> 
*      <li>content 1</li>
*      <li>content 2</li>
*      <li>content 3</li>
*  </ul>
*  
*  $('#news').innerfade({ 
*	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
*	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
*	  timeout: Time between the fades in milliseconds (Default: '2000'), 
*	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
* 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
*	  runningclass: CSS-Class which the container get’s applied (Default: 'innerfade'),
*	  children: optional children selector (Default: null)
*  }); 
*

// ========================================================= */


(function ($) {

    $.fn.innerfade = function (options) {
        return this.each(function () {
            $.innerfade(this, options);
        });
    };

    $.innerfade = function (container, options) {
        var settings = {
            'animationtype': 'fade',
            'speed': 'normal',
            'type': 'sequence',
            'timeout': 2000,
            'containerheight': 'auto',
            'runningclass': 'innerfade',
            'children': null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length - i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function () {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
                var last = Math.floor(Math.random() * (elements.length));
                setTimeout(function () {
                    do {
                        current = Math.floor(Math.random() * (elements.length));
                    } while (last == current);
                    $.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
            } else if (settings.type == 'random_start') {
                settings.type = 'sequence';
                var current = Math.floor(Math.random() * (elements.length));
                setTimeout(function () {
                    $.innerfade.next(elements, settings, (current + 1) % elements.length, current);
                }, settings.timeout);
                $(elements[current]).show();
            } else {
                alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
            }
        }
    };

    $.innerfade.next = function (elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function () {
                removeFilter($(this)[0]);
            });
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function () {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
    if (element.style.removeAttribute) {
        element.style.removeAttribute('filter');
    }
}

function SizeDropdownClick(ddlcontrol) {
    var tmpVal = $("#ddlsizechosenvalue");
    //alert("1) hidden field: " + tmpVal.id + ", value: " + tmpVal.value);

    //alert('Dropdown ' + ddlcontrol.id + ' changed! Value: ' + ddlcontrol.value);
    
    var tmpSizeValue = ddlcontrol.value;
    if (tmpSizeValue == "Vælg størrelse") {
        tmpSizeValue = "";
    }
    tmpVal.val(tmpSizeValue);

    hideSizeErrors();
}
function validateSizeChoice() {

    if ($(".ddlsize").length == 0) {
        return true;
    }
    
    var tmpVal = $("#ddlsizechosenvalue");
    //alert('validateSizeChoice(), ddlsizechosenvalue: ' + tmpVal.val());
    if (tmpVal.length != 0 && tmpVal.val() != "" && tmpVal.val() != "Vælg størrelse") {

        return true;
    }
    //debugger;
    //Show error message...
    showSizeErrors();
    return false;
}


function showSizeErrors() {

    //alert('showSizeErrors:');
    $(".errormsg .sizeerrmsg").empty();
    $(".errormsg").show();
    $(".errormsg").append("<span class='sizeerrmsg'>Der skal vælges en størrelse!</span>");
}
function hideSizeErrors() {
    
    var tmpVal2 = $("#ddlsizechosenvalue"); 
    //alert('hideSizeErrors(), tmpVal2.value: ' + tmpVal2.val() + ", tmpVal2.length is " + tmpVal2.length);  //tmpVal2.value
    var temVal3 = tmpVal2.val();
    if (temVal3 != "" && temVal3 != "Vælg størrelse") {
        $(".errormsg .sizeerrmsg").empty();
        //$(".errormsg").hide();
    }
}

function validate() {
    var lblMessage = document.getElementById("<%=lblValidation.ClientID%>");
    var nameErrorMessage = "";
    if (document.getElementById("<%=tbName.ClientID%>").value == "") {
        if (lblMessage != null) {
            lblMessage.innerHTML = "Udfyld navn";
            lblMessage.style.visibility = "visible";
        }
        document.getElementById("<%=tbName.ClientID%>").focus();
        return false;
    }
    if (document.getElementById("<%=tbEmail.ClientID %>").value == "") {
        //alert("Email id can not be blank");
        if (lblMessage != null) {
            lblMessage.innerHTML = "Udfyld email";
            lblMessage.style.visibility = "visible";
        }
        document.getElementById("<%=tbEmail.ClientID %>").focus();
        return false;
    }
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    var emailid = document.getElementById("<%=tbEmail.ClientID %>").value;
    var matchArray = emailid.match(emailPat);
    if (matchArray == null) {
        //alert("Your email address seems incorrect. Please try again.");
        if (lblMessage != null) {
            lblMessage.innerHTML = "Email adresse er forkert udfyldt. Prøv venligst igen.";
            lblMessage.style.visibility = "visible";
        }
        document.getElementById("<%=tbEmail.ClientID %>").focus();
        return false;
    }
    return true;
}
$(document).ready(function () {

    setTimeout(function () {
        $(".shopTopLevelTwoMenuRight_productAdded").animate({ height: 0, opacity: 0 }, 'slow');
    }, 3500);

    $(".onlinebenefits li").hover(
          function () {
              $(this).find('ul').addClass('showMe');
          },
          function () {
              $(this).find('ul').removeClass('showMe');
          }
        );

    /* $(".deliveryAdressChk input").click(
    function () {
    $(this).parent().parent().next().toggle();
    }
    );*/
    $('.onlinebenefits li ul').bgiframe();

    var ddlFarve = $('.ddlcolor');
    $('.ddlsizelabel').hide();
    //alert("ddlFarve   empty?" + (ddlFarve.length == 0));

    if (ddlFarve.length == 0) {
        $('.ddlsize').show();
        $('.ddlsizelabel').show();
    }
    else {
        $('.ddlsize').hide();
        //$('.ddlsizelabel').hide();
    }


    $(".onlinebenefits li").hover(
          function () {
              var $this = $(this),
                divclass = $this.attr('class');
              $(this).addClass('hoverMe' + divclass);
          },
          function () {
              var $this = $(this),
                divclass = $this.attr('class');
              $(this).removeClass('hoverMe' + divclass);
          }
        );


    $("ul.megadropdown").children("li").bind('mouseenter', function () {
        $(this).addClass('hover');
        //alert($(this).attr("class"));
    }).bind('mouseleave', function () {
        $(this).removeClass('hover');
        //alert($(this).attr("class"));
    });
    //$("ul.megadropdown li ul").bgiframe();




    $('#imagenav ul li:first').addClass('first');
    /*$('#imagenav ul li').mousedown(function() {
    $(this).parent().find('li').removeClass('active');
    $(this).addClass('active');            
    }) 
    */

    var jqOptions = {
        zoomWidth: 300,
        zoomHeight: 300,
        preloadText: 'Zoom funktionalitet startes...',
        showEffect: 'show',
        hideEffect: 'fadeout',
        fadeoutSpeed: 'slow',
        title: false
    };

    var jqOptionsFast = {
        zoomWidth: 300,
        zoomHeight: 300,
        preloadText: 'Zoom funktionalitet startes...',
        showEffect: 'show',
        hideEffect: 'fadeout',
        fadeoutSpeed: 'fast',
        title: true
    };

var $jq = $('.jqzoom');
    $jq.find('img').each(function () {
        src = $(this).attr('src');
        //src = $.browser.safari ? src + '?1' : src;
        $(this).attr('src', src);
    });

    var $jqfast = $('.jqzoomfast');
    $jqfast.find('img').each(function () {
        src = $(this).attr('src');
        //src = $.browser.safari ? src + '?1' : src;
        $(this).attr('src', src);
    });

    $jq.jqzoom(jqOptions);
    $jqfast.jqzoom(jqOptionsFast);

    /*
    src = $jq.find('img').attr('src');
    src = $.browser.safari ? src + '?1' : src;
    $jq.jqzoom(jqOptions).find('img').attr('src', src);
    */

    $('#imagenav ul li').mousedown(function () {
        var $this = $(this),
            src = $this.find('img').attr('src').replace('w=50', ''),
            index = $this.parent().find('li').index(this) + 1;
        src = src.replace('&h=50', '');
        if ($(this).parent().parent().prev('a').length > 0) {
            $(this).parent().parent().prev().attr('href', src + '?w=600').children('img').attr('src', src);
        } else {
            $(this).parent().parent().prev().attr('src', src);
        }
        $(this).parent().find('li').each(function (i) {
            if (i == (index - 1)) {
                $(this).addClass('active');
            } else {
                $(this).removeClass('active');
            }
        });
        $('.jqzoom').unbind().jqzoom(jqOptions);
        //$this.parent().find('li').removeClass('active');
        //$this.parent().find('li').eq(index-1).addClass('active');        
        //$(t'#cl11_UcColorAndSize_DdlColor option').attr('selected', '').eq(index).attr('selected', 'selected');

        //$('.ddlcolor option').attr('selected', '').eq(index).attr('selected', 'selected');
        $('.ddlcolor').attr('selectedIndex', index);

        // $(this).parent().find("li").each(function (i) {
        //     //console.log($(this));
        // });

        var ddlFarveValue = $('.ddlcolor option:selected').val();

        var idToShow = "colortoggle_" + ddlFarveValue.replace("{", "").replace("}", "").replace("-", "").replace("-", "").replace("-", "").replace("-", "");

        //alert('lige før ddlsize hide');
        $('.ddlsize').hide();

        $('.' + idToShow).show();
        $('.ddlsizelabel').show();



        var tmpSizeValue = $('.' + idToShow).val();
        if (tmpSizeValue == "Vælg størrelse") {
            tmpSizeValue = "";
        }
        var tmpHiddenSizeValue = $("#ddlsizechosenvalue");
        if (tmpHiddenSizeValue.length > 0) {
            tmpHiddenSizeValue.val(tmpSizeValue);
        }

        //alert('Lige inden hideSizeErrors()!');
        hideSizeErrors();
        //alert('idToShow' + idToShow);
        //InitSizes();
        //alert('idToShow' + idToShow);

    });




    //    function InitSizes() {
    //        var ddlFarveValue = $('.ddlcolor option:selected').val();
    //        //alert('What: ProductColorItemId: ' + ddlFarveValue);
    //        $.ajax({
    //            type: "POST",
    //            url: "/Handlers/GetProductSizesHandler.ashx",
    //            data: ({ ProductColorItemId: ddlFarveValue }),
    //            dataType: "json",
    //            cache: true,
    //            success: function (json) {

    //                //alert("SUCCESS!  Status: " + json["Status"]);

    //                $(".ddlsize >option").remove();
    //                var sizeDropdown = $('.ddlsize');
    //                jQuery.each(json, function (index, val) {
    //                    //alert('EACH VAL [' + index + ']: ' + val["Id"] + ', text: ' + val["SizeText"]);
    //                    //fill dropdown
    //                    $('.ddlsize').append("<option value=" + val["Id"] + ">" + val["SizeText"] + "</option>");
    //                });
    //            }
    //        });
    //    }


    //$('#ctl11_UcColorAndSize_DdlColor').change(function () {
    $('.ddlcolor').change(function () {
        //alert('Hej');
        var $this = $(this),
            index = $this.find('option').index($this.find('option:selected')) - 1;
        $('#imagenav ul li:eq(' + index + ')').trigger('mousedown');

        var ddlFarveValue = $('.ddlcolor option:selected').val();
        var idToShow = "colortoggle_" + ddlFarveValue.replace("{", "").replace("}", "").replace("-", "").replace("-", "").replace("-", "").replace("-", "");
        //alert('ddlcolor_change');
        $('.ddlsize').hide();

        if (ddlFarveValue != "Vælg farve" && ddlFarveValue != "") {
            $('.' + idToShow).show();
            $('.ddlsizelabel').show();
        }
        else {
            $('.ddlsizelabel').hide();
        }


        var tmpSizeValue = $('.' + idToShow).val();
        if (tmpSizeValue == "Vælg størrelse") {
            tmpSizeValue = "";
        }
        var tmpHiddenSizeValue = $("#ddlsizechosenvalue");
        if (tmpHiddenSizeValue.length > 0) {
            tmpHiddenSizeValue.val(tmpSizeValue);
        }
        hideSizeErrors();
        //alert('idToShow' + idToShow);
        //InitSizes();
    });

    $('#frontPageImages').innerfade({
        speed: 'slow',
        timeout: 10000,
        type: 'sequence',
        containerheight: '220px'
    });
    $('ul.megadropdown a[href$="#"]').addClass('numb');
    $('ul.megadropdown a[href$="#"]').click(function () {
        return false;
    });

    //    $('.ddlsize').hide();

    // bind to click on area20 boxes
    $('div.area20_boxLT, div.area20_boxRT').hover(function () { $(this).addClass('hover'); }, function () { $(this).removeClass('hover'); });

    // online konkurrence script    
    $('div.pictureCompetetion li').hover(function () { $(this).addClass('hover'); }, function () { $(this).removeClass('hover'); });

    $('div.pictureCompetetion li a').click(function () {
        $(this).parent().parent().find('li').removeClass('selected');
        $(this).parent().addClass('selected');
        $(this).parent().parent().parent().find('span.selectedImageText').fadeIn();
        $(this).parent().parent().parent().find('span.imageTextDisplay').text($(this).find('img').attr('alt'));
        $(this).parent().parent().parent().find('input:hidden').val($(this).find('img').attr('alt'));
    });

    var foundElement = $('div.pictureCompetetion input:hidden');
    if (foundElement.length > 0) {
        if (foundElement.val().length > 0) {
            var altText = foundElement.val();

            $('div.pictureCompetetion li img').each(function () {
                if ($(this).attr('alt') == altText) {
                    $(this).parent().addClass('selected');
                }
            });
        }

    }

});

