﻿/*function blurAnchors() {
if (document.getElementsByTagName) {
var a = document.getElementsByTagName("a");
for (var i = 0; i < a.length; i++) {
a[i].onfocus = function() { this.blur() };
}
}
}
window.onload = blurAnchors;*/


Sys.Application.add_load(function() {

    var currentTallest = 0;
    $("#infocenter ul li").each(function(i) {
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
    });


    //Set height for infocenter li's
    $('#infocenter ul').children('li').css({ 'height': currentTallest });
    $('#infocenter ul ul').children().removeAttr("style");


    //Set hight for answer
    currentTallest = 0;
    $(".faqs .answer").each(function(i) {
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
    });

    $('.faqs ').css({ 'height': currentTallest });



    $.each($("a.knapp, a.mainknapp"), function(i, v) {
        var theElement = $(v);
        var theHtml = theElement.html();
        
        if ($(v).find('span').length == 0)
            theElement.html("<span>" + theHtml + "</span>");
    });




    $("#ChooseSize").click(function() {
        $("#AvaliableSizes").toggle();
    });


    $("#nav-produkter li .highslide-html-content").each(
        function() {
            var child = $(this);

            if (($("#" + child.attr('id') + " .submeny")).children().size() <= 1) {
                child.attr('class', 'highslide-html-content highslide-html-content-small');
            }
        });


    $(".dropdown-colors").change(function() {

        var str = "";
        $(".dropdown-colors option:selected").each(function() {
            str += $(this).text() + " ";
        });
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();
        str = str.toLowerCase().replace("\\", "").replace("/", "").replace("-", "").replace(" ", "").replace("&", "").replace("æ", "").replace("ø", "").replace("å", "").trim();


        $(".Color" + str).click();
    });






});


/* =========================================================
Datetime Picker 
*/
$(function() {
    if (jQuery.datepicker) {
        $(".datepicker").datepicker({
            showWeek: true,
            firstDay: 1,
            dateFormat: 'dd.mm.yy',
            changeYear: true,
            showOtherMonths: true,
            selectOtherMonths: true,
            weekHeader: 'Uke'

        });
    }
});

$(function() {
    if (jQuery.datepicker) {
        $('.datetimepicker').datepicker({
            duration: '',
            showTime: true,
            constrainInput: true,
            time24h: true,
            showWeek: true,
            firstDay: 1,
            dateFormat: 'dd.mm.yy',
            timeFormat: 'hh.MM.ss',
            changeYear: true,
            showOtherMonths: true,
            selectOtherMonths: true,
            weekHeader: 'Uke'
        });
    }
});

/* =========================================================
Default button
*/

$(document).ready(function() {
    var $btn = $('.form_submit');
    var $form = $btn.parents('.form');

    $form.keypress(function(e) {
        if (e.which == 13 && e.target.type != 'textarea')
        { if ($btn[0].type == 'submit') $btn[0].click(); else eval($btn[0].href); return false; }
    });
});


/* =========================================================
Watermark
*/

$(function() {
    swapValues = [];
    $(".swap_value").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).css("color", "black");
                $(this).val("");
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });
});


/* =========================================================
Simple popup
*/

$(function() {
    $(".btn-slide").hover(function() {
        $("#pop-panel").slideToggle(300);
        return false;
    });
});


/* =========================================================
360 product view (rotatestorm)
*/

$(function() {

    //Rootating stormberg






});

function Roate360(url, images) {

    $('.product-image').hide();
    $('.blackback').show('fast');

    var arrstorm = []
    for (var x = 1; x <= images; x++)
        arrstorm.push(url + x + ".jpg");

    $(".rotatestorm").threesixty({ images: arrstorm, method: 'mousemove', 'cycle': 3 });
    $(".hold360").show('fast');
    $(".show360").hide();

};

function Close360() {
    $(".blackback").hide('fast')
    $(".hold360").hide('fast');
    $(".show360").show();
    $('.product-image').show();
};

function CloseYouTube() {
    $('.blackback').hide();
    $('.holdYouTube').hide('fast');
    $('.product-image').show();
    $('.innerYouTube').html('');
};

function OpenYouTube(youtubekey) {

    var youtubewidth = 605;
    var youtubeheight = 365;
    /*        
    var youtube = "<object type='application/x-shockwave-flash' background=\"ffffff\" color1=\"ffffff\" color2=\"ffffff\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\">" +
    "<param name=\"movie\" value=\"/youtube/v/" + youtubekey + "&enablejsapi=1&autoplay=1&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param>" +
    "<embed src=\"/youtube/v/" + youtubekey + "&background=ffffff&color1=ffffff&color2=ffffff&enablejsapi=1&autoplay=1&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\"></embed>" +
    "</object>";
    */

    var youtube = "<object type=\"application/x-shockwave-flash\" background=\"ffffff\" color1=\"ffffff\" data=\"/youtube/v/" + youtubekey + "&enablejsapi=1&autoplay=1&hl=en&fs=1&\" color2=\"ffffff\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\">" +
    "<param name=\"movie\" value=\"/youtube/v/" + youtubekey + "&enablejsapi=1&autoplay=1&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param>" +
    "<embed src=\"http://www.youtube.com/v/" + youtubekey + "&background=ffffff&color1=ffffff&color2=ffffff&enablejsapi=1&autoplay=1&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\"></embed>" +
    "</object>";


    $('.product-image').hide();
    $('.blackback').show('fast');
    $('.innerYouTube').html(youtube);
    $('.holdYouTube').show('fast');

};

function CloseYouTubeContainer(containerName) {
    $('.blackbackContainer').hide();
    $('#' + containerName).hide('fast');
    $('.product-image').show();
    $('.innerYouTube').html('');
};

function OpenYouTubeContainer(youtubekey, containerName) {

    var youtubewidth = 605;
    var youtubeheight = 365;

    var youtube = "<object type=\"application/x-shockwave-flash\" data=\"/youtube/v/" + youtubekey + "&background=ffffff&color1=ffffff&color2=ffffff&enablejsapi=1&autoplay=1&hl=en&fs=1&\" background=\"ffffff\" color1=\"ffffff\" color2=\"ffffff\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\">" +
        "<param name=\"movie\" value=\"/youtube/v/" + youtubekey + "&enablejsapi=1&autoplay=1&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param>" +
        "<embed src=\"http://www.youtube.com/v/" + youtubekey + "&background=ffffff&color1=ffffff&color2=ffffff&enablejsapi=1&autoplay=1&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" + youtubewidth + "\" height=\"" + youtubeheight + "\"></embed>" +
        "</object>";

    $('.product-image').hide();
    $('.blackbackContainer').show('fast');
    $('.innerYouTube').html(youtube);
    $('#' + containerName).show('fast');


};

/* =========================================================

// 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');
    }
}



$(document).ready(
				function() {
				    $('#news').innerfade({
				        animationtype: 'slide',
				        speed: 750,
				        timeout: 2000,
				        type: 'sequence',
				        containerheight: '1em'
				    });

				    $('ul#samarbeid').innerfade({
				        speed: 1000,
				        timeout: 5000,
				        type: 'sequence',
				        containerheight: '220px'
				    });


				    $('ul.slideshow').innerfade({
				        speed: 1000,
				        timeout: 5000,
				        type: 'random_start'

				    });

				    $('.fade').innerfade({
				        speed: 1000,
				        timeout: 6000,
				        type: 'random_start',
				        containerheight: '1.5em'
				    });

				    $('.adi').innerfade({
				        speed: 'slow',
				        timeout: 5000,
				        type: 'random',
				        containerheight: '150px'
				    });

				}
				);

                /******************************
                Facebook likes button - All: <div id="fb-like-button-text"></div>
                App ID: '38278479589'
                ******************************/
				$(document).ready(function() {
				    var pageUrl = $(location).attr('href');
				    pageUrl = escape(pageUrl);
				    var inner = '<iframe src="http://www.facebook.com/plugins/like.php?href=' + pageUrl + '&amp;layout=standard&amp;show_faces=true&amp;width=300&amp;action=like&amp;colorscheme=light&amp;height=23&amp;locale=nb_NO" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:23px;" allowtransparency="true"></iframe>';
				    $('#fb-like-button-text').html(inner);
				});
				
/*************************
Helper to fix issues with jquery causing updatepanel abort
**************************/
				var PageRequestManagerEx =
{
    _initialized: false,

    init: function() {
        if (!PageRequestManagerEx._initialized) {
            var _prm = Sys.WebForms.PageRequestManager.getInstance();
            var _callQueue = new Array();
            var _executingElement = null;

            _prm = Sys.WebForms.PageRequestManager.getInstance();

            _prm.add_initializeRequest(initializeRequest);
            _prm.add_endRequest(endRequest);

            PageRequestManagerEx._initialized = true;
        }

        function initializeRequest(sender, args) {
            if (_prm.get_isInAsyncPostBack()) {
                //if we are here that means there already a call pending.

                //Get the element which cause the postback
                var postBackElement = args.get_postBackElement();

                //We need to check this otherwise it will abort the request which we made from the
                //end request
                if (_executingElement != postBackElement) {
                    //Item does not match which means it is another control
                    //which request the update, so cancel it temporary and 
                    //add it in the call queue
                    args.set_cancel(true);
                    Array.enqueue(_callQueue, postBackElement);
                }

                //Reset it as we are done with our matching
                _executingElement = null;
            }
        }

        function endRequest(sender, args) {
            //Check if we have a pending call
            if (_callQueue.length > 0) {
                //Get the first item from the call queue and setting it
                //as current executing item
                _executingElement = Array.dequeue(_callQueue);

                //Now Post the from which will also fire the initializeRequest
                _prm._doPostBack(_executingElement.id, '');
            }
        }
    }
}

