/* jcarousellite_1.0.1.pack.js|customers */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.1g.1w=6(o){o=$.1f({r:n,x:n,N:n,17:q,J:n,L:1a,16:n,y:q,u:12,H:3,B:0,k:1,K:n,I:n},o||{});8 G.R(6(){p b=q,A=o.y?"15":"w",P=o.y?"t":"s";p c=$(G),9=$("9",c),E=$("10",9),W=E.Y(),v=o.H;7(o.u){9.1h(E.D(W-v-1+1).V()).1d(E.D(0,v).V());o.B+=v}p f=$("10",9),l=f.Y(),4=o.B;c.5("1c","H");f.5({U:"T",1b:o.y?"S":"w"});9.5({19:"0",18:"0",Q:"13","1v-1s-1r":"S","z-14":"1"});c.5({U:"T",Q:"13","z-14":"2",w:"1q"});p g=o.y?t(f):s(f);p h=g*l;p j=g*v;f.5({s:f.s(),t:f.t()});9.5(P,h+"C").5(A,-(4*g));c.5(P,j+"C");7(o.r)$(o.r).O(6(){8 m(4-o.k)});7(o.x)$(o.x).O(6(){8 m(4+o.k)});7(o.N)$.R(o.N,6(i,a){$(a).O(6(){8 m(o.u?o.H+i:i)})});7(o.17&&c.11)c.11(6(e,d){8 d>0?m(4-o.k):m(4+o.k)});7(o.J)1p(6(){m(4+o.k)},o.J+o.L);6 M(){8 f.D(4).D(0,v)};6 m(a){7(!b){7(o.K)o.K.Z(G,M());7(o.u){7(a<=o.B-v-1){9.5(A,-((l-(v*2))*g)+"C");4=a==o.B-v-1?l-(v*2)-1:l-(v*2)-o.k}F 7(a>=l-v+1){9.5(A,-((v)*g)+"C");4=a==l-v+1?v+1:v+o.k}F 4=a}F{7(a<0||a>l-v)8;F 4=a}b=12;9.1o(A=="w"?{w:-(4*g)}:{15:-(4*g)},o.L,o.16,6(){7(o.I)o.I.Z(G,M());b=q});7(!o.u){$(o.r+","+o.x).1n("X");$((4-o.k<0&&o.r)||(4+o.k>l-v&&o.x)||[]).1m("X")}}8 q}})};6 5(a,b){8 1l($.5(a[0],b))||0};6 s(a){8 a[0].1k+5(a,\'1j\')+5(a,\'1i\')};6 t(a){8 a[0].1t+5(a,\'1u\')+5(a,\'1e\')}})(1x);',62,96,'||||curr|css|function|if|return|ul|||||||||||scroll|itemLength|go|null||var|false|btnPrev|width|height|circular||left|btnNext|vertical||animCss|start|px|slice|tLi|else|this|visible|afterEnd|auto|beforeStart|speed|vis|btnGo|click|sizeCss|position|each|none|hidden|overflow|clone|tl|disabled|size|call|li|mousewheel|true|relative|index|top|easing|mouseWheel|padding|margin|200|float|visibility|append|marginBottom|extend|fn|prepend|marginRight|marginLeft|offsetWidth|parseInt|addClass|removeClass|animate|setInterval|0px|type|style|offsetHeight|marginTop|list|jCarouselLite|jQuery'.split('|'),0,{}))
/* page.js|customers */
// inits script
function initPageJs() {
	// global vars get set
	accessibleInputs();
	// make accesible hr-elements
	$("hr[class!='mdAccess']").wrap("<div class='hr'></div>");
	// init galleryslider & galleryroll
	initGallerySlider();
	initGalleryRoll();
	// assign popup function to all a-elements with mdPop class
	assignPop();
	// clean breadcrumb in popup
	$("#mdPopCrumb dd:eq(0) a").css({ background:"none", paddingLeft:"2px" });
	// assign extended popup function to all a-elements with mdPopup class
	popupMaker();
	// assign print functionality
	assignPrint();
	// make sure related links open in right window from popup
	assignRelatedGalleryLink();
	// progressbar
	fillProgressBar();
	// pco opinion
	PcoOpinionBannerCookie();
	PcoOpinionLaunch();	
}

// moves labels value to inputs if class 'mdValueToInput' is present & then adds focus/blur to inputs
function accessibleInputs(){
	$("label.mdValueToInput[for]").each(function(i){
		// fill input fields with labeltext - html tags
		var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
		var newVal = this.innerHTML.replace(regexp,"");
		//if el is type=input or textarea
		if($("#"+this.htmlFor).is("input") || $("#"+this.htmlFor).is("textarea")){
			if(  ($("#"+this.htmlFor).val() == "") || ($("#"+this.htmlFor).val() == newVal)  ){
				$("#"+this.htmlFor).attr("value",newVal);
				// create onclick/blur functionality
				$("#"+this.htmlFor).focus(function(){if(this.value == newVal) this.value = "";});
				$("#"+this.htmlFor).blur(function(){if(this.value == "") this.value = newVal;});
			}
		// if el is select	
		} else if($("#"+this.htmlFor).is("select")){
			var orgOptions = $("#"+this.htmlFor).html();
			$("#"+this.htmlFor).html("")
			strSelected = ' selected="selected"';
			if(orgOptions.indexOf("selected=") > -1) strSelected = "";
			newOptions = "<option"+strSelected+">"+newVal+"</option>"+orgOptions;
			$("#"+this.htmlFor).html(newOptions)		}
			// hide label
			$(this).hide();
	})
	cleanForms();
}

// makes sure that label values are not submitted to forms
function cleanForms(){
	$("form:has(label.mdValueToInput)").submit(function(){
		$("label.mdValueToInput[for]").each(function(){
			// check if value is same as label
			var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
			var newVal = this.innerHTML.replace(regexp,"");
			if($("#"+this.htmlFor).attr("value") == newVal){
				$("#"+this.htmlFor).attr("value","");
			}
		})
	})
}

function initGallerySlider(){
	var amount = $(".mdGallerySliderInner li").length;
	var totalwidth = 0;
	$(".mdGallerySliderInner li").each(function(){totalwidth += $(this).width();})
	
	if($(".mdGallerySliderInner").width() < totalwidth){
		$(".mdGallerySlider div").not($(".mdGallerySliderInner")).css({display:"block"})
		$(".mdGallerySliderInner").jCarouselLite({
			btnNext: ".mdNext",
			btnPrev: ".mdPrev",
			visible: amount
		});	
	} else {
		$(".mdGallerySliderInner ul").css("margin",0)
	}
}

function initGalleryRoll(){
	var ulWidth = 0, afterSelected = 0, galleryRollWidth = $(".mdGalleryRoll").width();
	$(".mdGalleryRoll li").each(function(){
		ulWidth += $(this).width();
		$(this).css({"opacity":"0.5","-moz-opacity":"0.5","filter":"alpha(opacity=50)"});
		if($(this).attr("class") == "selected"){
			afterSelected = 0;
			$(this).css({"opacity":"1","-moz-opacity":"1","filter":"alpha(opacity=100)"});
		}	
		afterSelected += $(this).width();
		$(this).not(".selected").hover(function(){
		  $(this).css({"opacity":"1","-moz-opacity":"1","filter":"alpha(opacity=100)"});
		},function(){
		  $(this).css({"opacity":"0.5","-moz-opacity":"0.5","filter":"alpha(opacity=50)"});
		});
				
	})
	if(ulWidth < galleryRollWidth){
		$(".mdGalleryRoll").siblings().css({display:"none"});
	} else {
		var offset = ((ulWidth - afterSelected) - (galleryRollWidth / 2)) * -1;
		if(offset > 0) offset = 0
		if(afterSelected < (galleryRollWidth / 2)){
			offset += (galleryRollWidth / 2) - afterSelected;
		}
		$(".mdGalleryRoll ul").css({width:ulWidth+"px",margin:"0 0 0 "+offset+"px"});
	}
}
	
function assignPop(){
	$(".mdPop").click(function(){
		window.open($(this).attr('href'), 'bbPop', 'width=990,height=700');
        return false;
    });
}

function assignPrint(){
	$(".mdPrint, .mdIconPrint").click(function(){
		window.print();
		return false;
	})
}

function popupMaker() {
	$("a[@class^='mdPopup']").click(function() {
		var objClass=$(this).attr("class");
		var objId=$(this).attr("id");
		var popupWidth='500';
		var popupHeight='350';
		if(objClass.length>7) {
			widthHeightArray=objClass.substring(7).split("x");
			popupWidth=widthHeightArray[0];
			popupHeight=widthHeightArray[1];
		}
		var popupLeft='300';
		var popupTop='200';
		if(screen.availWidth && screen.availHeight) {
			var popupLeft=((screen.availWidth/2)-(popupWidth/2));
			var popupTop=((screen.availHeight/2)-(popupHeight/2));
		}
		if(objId) {
			var winName='popWin_'+objId;
		}else{
			var winName='popWin_'+(Math.floor(Math.random()*1000000));
		}
		window.open(this.href, winName, ('width='+popupWidth+', height='+popupHeight+', left='+popupLeft+', top='+popupTop+'')); 
		return false;
	});
}

function open_prod_search_result() {
	var prodtype = $("#prodtype").attr("value");
	var prodcolor = $("#prodcolor").attr("value");
	var prodprice = $("#prodprice").attr("value");
	var args = '';
	if (prodtype != 0) {
		args += prodtype;
	}
	if (prodcolor != 0) {
		if (args != '') {
			args += '%2C';
		}
		args += prodcolor;
	}
	var url = 'http://bobedre.dk/gallery-filter/' + args + '?popup=gallery';
	if (prodprice != 'Indtast max. pris: ') {
		url += '&price[max]='+prodprice;
	}
	window.open(url,'winName','width=1000,height=750');
	return false;
}

function assignRelatedGalleryLink() {
  $('#relatedGalleryLink').click(function(){
    if (window.opener == null) {
      window.open($(this).attr('href')); 
    } else {
      window.opener.location = $(this).attr('href'); 
      window.opener.focus(); 
    }
    return false;
  });
}

function fillProgressBar(){
	$("td.mdProgress").each(function(){
		$(this).html('<div class="mdProgress"><div class="mdProgressBar"><div class="mdProgressBarInner">'+$(this).text()+'</div></div></div>').find(".mdProgressBarInner").css({"width":parseInt($(this).text())+"%"});
	})
	$("div.mdTestProgressBar").each(function(){
		$(this).css({"width":parseInt($(this).find("strong").text())+"%"})
	})
}

// Surveypopup unload
function PcoOpinionLaunch() {
	$(window).unload(function(){
		if (typeof pcoOpinion != 'undefined') {
			PcoOpinionPopup();
		}
	})
}

// Surveypopup bannerclick
function PcoOpinionBannerCookie(){	
	if (typeof pcoOpinion != 'undefined') {		
		// Get params from emediate URL
		var emediate_params = new Array();
		emediate_params = PcoOpinionGetBannerParams();
		if (emediate_params['type']) {
			$(".mdAd930x180 "+emediate_params['type']).click(function(){
				// Set a unique cookie for this banner
				$.cookie("pco_banner_cookie_"+pcoOpinion, pcoOpinion, { expires: 365 });
				PcoOpinionPopup();
			});
		}
	}
}

function PcoOpinionGetBannerParams() {
	var params = new Array();

	// Look for a:href
	if ($(".mdAd930x180").find("a:first").attr("href")) {
		params['type'] = 'a';
		params['elHref'] = $(".mdAd930x180").find("a:first").attr("href");
		params['indexer'] = "emediate.eu/eas/";
		params['offset'] = 16;
		return params;
	}
	// Look for embed:src
	else if ($(".mdAd930x180").find("embed:first").attr("src")) {
		params['type'] = 'embed';
		params['elHref'] = $(".mdAd930x180").find("embed:first").attr("src");
		params['indexer'] = "emediate.eu/eas?";
		params['offset'] = 16;
		return params;	
	}
	// Look for second script:src
	else if ($(".mdAd930x180").find("script:eq(1)").attr("src")) {
		params['type'] = 'script';
		params['elHref'] = $(".mdAd930x180").find("script:eq(1)").attr("src");
		params['indexer'] = "emediate.eu/eas/";
		params['offset'] = 16;
		return params;
	}
	
	// Else the banner is not supported
	else {
		return false;
	}	
}

// Surveypopup
function PcoOpinionPopup() {
	// Continue if user havent seen this ad/survey before
	if (!$.cookie("pco_opinion_uniquekey_"+pcoOpinion)) {
		// Get unique foreignKey for user
		if($.cookie("pco_opinion_uniquekey_"+pcoOpinion)) {
			var uniquekey = $.cookie("pco_opinion_uniquekey_"+pcoOpinion);
		} else {
			var uniquekey = Math.floor(Math.random()*1000000);
		}
		
		// Get params from emediate URL
		var emediate_params = new Array();
		emediate_params = PcoOpinionGetBannerParams();
		
		if (emediate_params['indexer'] && emediate_params['offset']) {
			// Set unique cookie for this survey
			$.cookie("pco_opinion_uniquekey_"+pcoOpinion, uniquekey, { expires: 365 });
			
			// And generate popup
			var emediate_codes 	= $.emediate_getUrlVars(emediate_params['elHref'], emediate_params['indexer'], emediate_params['offset']);
			var cu_code 		= emediate_codes["cu"];
			var camp_code		= emediate_codes["camp"];
			var clicked_banner  = $.cookie("pco_banner_cookie_"+pcoOpinion) ? 1 : 0;			
			var survey_url = "http://bonnier.opinion.peytz.dk/survey.php?sid="+pcoOpinion+"&fk="+uniquekey+"&cu="+cu_code+"&camp="+camp_code+"&clicked_banner="+clicked_banner;
			// Open the popup survey
			window.open(survey_url, "pco_survey_"+uniquekey, ("width=800, height=600"));
			return false;
		}
	}
	else {
		return false;
	}
}

// Get all or a single parameter from an emediate ad
$.extend({
  emediate_getUrlVars: function(elHref, indexer, offset){
    var vars = [], hash;
    var hashes = elHref.slice(elHref.indexOf(indexer) + offset).split('::');
    for(var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
    return vars;
  },
  emediate_getUrlVar: function(elHref, indexer, offset, name){
    return $.emediate_getUrlVars(elHref, indexer, offset)[name];
  }
});

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function(){
  initPageJs();
});
