﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
$("html").addClass("js");

//DD_roundies.addRule('#head', '5px');
					
jQuery.noConflict();

/*	jQuery Color Animations
	Copyright 2007 John Resig
	Released under the MIT and GPL licenses.
*/
(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end)}fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")"}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3){return color}if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)){return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])]}if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)){return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55]}if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)){return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)]}if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)){return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)]}return colors[jQuery.trim(color).toLowerCase()]}function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body")){break}attr="backgroundColor"}while(elem=elem.parentNode);return getRGB(color)};var colors={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);
 
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

(function($) {
	/*
	jQuery extension to get URL parameters		
	*/
	$.extend({
		getURLParam: function(_param, _href) {
			var sReturn = "";
			if (!_href) {
				_href = window.location.href;
			}
			var bFound = false;
			var cmpstring = _param + "=";
			var cmplen = cmpstring.length;
			if (_href.indexOf("?") > -1) {
				var strQueryString = _href.substr(_href.indexOf("?") + 1).replace("&amp;", "&");
				var aQueryString = strQueryString.split("&");
				for (var iParam = 0; iParam < aQueryString.length; iParam++) {
					if (aQueryString[iParam].substr(0, cmplen) == cmpstring) {
						var aParam = aQueryString[iParam].split("=");
						sReturn = aParam[1];
						bFound = true;
						break;
					}
				}
			}
			if (bFound == false) {
				return null;
			}
			return sReturn;
		}
	});

	/*
	Highlight function
	*/
	$.fn.highlight = function(options) {
		return this.each(function() {
			var settings = jQuery.extend({
				color: "#ffff99",
				duration: "normal",
				easing: "linear"
			}, options);
			$(this).animate(
				{ backgroundColor: settings.color },
				settings.duration,
				settings.easing,
				function() {
					$(this).animate({ backgroundColor: "#ffffff" }, "normal")
				}
			);
		});
	};
	/*
	Add "name" to serialization
	*/
	$.fn.addToSerialize = function() {
		return "&" + $(this).attr("name") + "=" + $(this).val();
	}
	// add new effect to the tabs
	if ($.tools != undefined && $.tools.tabs != undefined) {
		var _fadeOutSpeed = "normal";
		var _fadeInSpeed = "normal";
		var _slideDownSpeed = "fast";
		if ($.browser.msie && $.browser.version < 8) {
			_fadeOutSpeed = 0;
			_fadeInSpeed = 0;
		}

		var effectSlide = function(i, done) {
			var _this = this;
			_this.getCurrentPane().find(".image").stop(true, true);
			_this.getCurrentPane().removeClass("active")
			.find(".image").fadeOut(_fadeOutSpeed);
			_this.getPanes().eq(i).addClass("active").show()
			 .find(".image").fadeIn(_fadeInSpeed);
		}
		$.tools.tabs.addEffect("slideNoText", effectSlide);

		var effectSlideWithText = function(i, done) {
			var _this = this;
			_this.getPanes().find(".text").stop(true, true);
			_this.getCurrentPane().find(".image").stop(true, true);
			_this.getCurrentPane().removeClass("active")
			.find(".text").slideUp(0)
			.end()
			.find(".image").fadeOut(_fadeOutSpeed);
			_this.getPanes().eq(i).addClass("active").show()
			 .find(".image").fadeIn(_fadeInSpeed)
			 .end()
			 .find(".text").slideDown(_slideDownSpeed);
		}
		$.tools.tabs.addEffect("slideWithText", effectSlideWithText);
	}
	// tooltip efftects
	if ($.tools != undefined && $.tools.tooltip != undefined) {
		var show = function(done) {
			var conf = this.getConf(), tip = this.getTip();
			tip.animate({opacity: 1}, conf.fadeInSpeed, done).show();
		}
		
		var hide = function(done) {
			var conf = this.getConf(), tip = this.getTip();
			tip.animate({opacity: 0}, conf.fadeOutSpeed, function(){
				$(this).hide();
				done.call();
			});
		}
		
		$.tools.tooltip.addEffect("fading", show, hide);
	}
})(jQuery);

/*	Scripts */
jQuery(function ($) {
    Engine = {
        fixes: {
            // Hover state for IE
            hoverState: function () {
                if ($.browser.msie && $.browser.version < 9) {
                    $('input.button, button.button, div.comment')
						.hover(
							function () {
							    $(this).addClass('hover');
							},
							function () {
							    $(this).removeClass('hover');
							}
						)
                }
            },
            // Focus state for IE
            focusState: function () {
                if ($.browser.msie && $.browser.version < 9) {
                    $('input.button, button.button')
						.focus(function () {
						    $(this).addClass('focus');
						})
						.blur(function () {
						    $(this).removeClass('focus');
						});
                }
            },
            // Focus state for IE
            roundCorners: function () {
                if ($.browser.msie && $.browser.version < 9) {
                    //					DD_roundies.addRule('#head', '5px');
                }
            }
        },
        ui: {
            // Youtube video links
            youtubeLinks: function () {
                $("#main a.youtube").each(
					function () {
					    var url = $(this).attr("href");
					    if (!url) { return false; }
					    var v = $.getURLParam("v", url);
					    if (!v) { return false; }
					    var w = $.getURLParam("diswidth", url);
					    if (!w) { w = 460; }
					    var h = $.getURLParam("disheight", url);
					    if (!h) { h = 285; }
					    $(this).find("img").attr("width", w).attr("height", h);
					    $(this).attr("id", v);
					    var flashvars = {};
					    var params = { wmode: "opaque", allowfullscreen: "true", allowscriptacess: "always", bgcolor: "#ffffff" };
					    var attributes = {};
					    //						alert("http://www.youtube.com/v/" + v + "=null&fs=1&color1=0x00ff00&color2=0x80ff00&border=0");

					    swfobject.embedSWF("http://www.youtube.com/v/" + v + "&fs=1&color1=0x00ff00&color2=0x80ff00&border=0", v, w, h, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
					}
				)
            },
            // Search field
            searchField: function () {
                var $search = $("#search input.text");
                if ($search.length) {
                    $search
						.attr("value", $search.attr("title"))
						.focus(function () {
						    if (this.value == this.title) {
						        this.value = "";
						    }
						})
						.blur(function () {
						    if (this.value == "") {
						        this.value = this.title;
						    }
						});
                }
            },
            // Tabbox
            tabBox: function () {

                var $tabbox = $("div.tabbox");
                var $tabboxItem = $tabbox.find("div.item");
                var $tabboxNavigation = $tabbox.find("div.navigation");

                $tabboxItem.find("a.link").each(function () {
                    $(this).parent().parent().prepend("<a href=\"" + $(this).attr("href") + "\" title=\"" + $(this).attr("title") + "\" class=\"largelink\"></a>");
                });

                $tabboxItem.find("div.text").slideUp(0);
                $tabboxItem.find("div.image").fadeOut(0);

                $("div.navigation")
					.tabs(".tabbox > .item", {
					    effect: "slideNoText",
					    fadeOutSpeed: "fast",
					    event: "mouseover",
					    rotate: true
					})
					.slideshow({
					    autoplay: true,
					    interval: 4000
					});

                var tabboxAPI = $("div.navigation").tabs(".tabbox > .item", {
                    api: true
                });

                $(".tabbox")
					.mouseenter(function (event) {
					    event.preventDefault()
					    tabboxAPI.getConf().effect = "slideWithText";
					    tabboxAPI.getCurrentPane().find("div.text").slideDown("fast");
					    //$("body").css("background-color", "red");
					})
					.mouseleave(function (event) {
					    event.preventDefault()
					    tabboxAPI.getConf().effect = "slideNoText";
					    tabboxAPI.getCurrentPane().find("div.text").slideUp("fast");
					    //$("body").css("background-color", "white");
					});
                $(".tabbox .navigation a")
					.hover(function (event) {
					    event.preventDefault()
					    tabboxAPI.getConf().effect = "slideWithText";
					    tabboxAPI.getCurrentPane().find("div.text").slideDown("fast");
					    //$("body").css("background-color", "blue");
					});

            },
            // Campaigns  
            campaigns: function () {
                var $campaign = $("#main div.campaign");
                $campaign.hoverIntent(
						function () {
						    $(this).find("div.text").slideDown("fast");
						},
						function () {
						    $(this).find("div.text").slideUp(0);
						}
					)
                $("#main div.campaign h2.header a").each(function () {
                    $(this).parent().parent().prepend("<a href=\"" + $(this).attr("href") + "\" title=\"" + $(this).attr("title") + "\" class=\"largelink\"></a>");
                });
                $campaign.find("div.text").slideUp(0);

            },
            // TabSlider
            tabSlider: function () {
                // setup ul.tabs to work as tabs for each div directly under div.panes 
                $("#main div.tabs ul").tabs("div.panes > div");
                $("#main div.scrollable").scrollable({ size: 4 });
            },
            // Print link
            printLink: function () {
                $("#main a.print").click(function () {
                    window.print();
                    return false;
                })
            },
            // Print link
            expose: function () {
               

                $(".expose").bind("click keydown", function () {
                    $(this).expose("#000");
                });
            },
            // Facebook link
            facebookLink: function () {

                $("#main a.share").click(function () {
                    u = location.href;
                    t = document.title;
                    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
                    return false;
                })
            },
			// Tooltips
			Tooltip: function( img ) {
				img = $(img).removeAttr("onmouseover");
				if(img.is("[title]")) {
					img
					.css("cursor", "pointer")
					.tooltip({position: "top left", layout: '<div><b class="arrow"></b></div>', tipClass: 'tooltip tooltip-leftside', effect: 'fading', fadeInSpeed: 200, fadeOutSpeed: 100, opacity: 0})
					.mouseenter()
					.click(function(e){
						var api = $(this).data("tooltip");
							api.hide();
							api.show();
					});
				}
			}
        }
    };
});

/*
	sikkertrafik DOM-ready
*/
jQuery(document).ready(function($){
	Engine.fixes.hoverState();
	Engine.fixes.focusState();
	Engine.fixes.roundCorners();
	Engine.ui.searchField();
	Engine.ui.tabBox();
	Engine.ui.campaigns();
	Engine.ui.tabSlider();
	Engine.ui.printLink();
	Engine.ui.facebookLink();
	Engine.ui.expose();
});
/*
	Runs when the page is fully loaded including graphics.
*/
jQuery(window).load(function () {
	Engine.ui.youtubeLinks();
});

