/*
Author: Mitch Köhler <m.koehler@cabalon.de>
Copyright (c) 2011, Cabalon.
All rights reserved.

This software is based on jQuery and uses jQueryTools and Douglas Crockford's json2.js.
*/
$.extend({URLEncode:function(c){var o="";var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;while(x<c.length){var m=r.exec(c.substr(x));if(m!=null&&m.length>1&&m[1]!=""){o+=m[1];x+=m[1].length}else{if(c[x]==" "){o+="+"}else{var d=c.charCodeAt(x);var h=d.toString(16);o+="%"+(h.length<2?"0":"")+h.toUpperCase()}x++}}return o},URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;while((m=r.exec(o))!=null&&m.length>1&&m[1]!=""){b=parseInt(m[1].substr(1),16);t=String.fromCharCode(b);o=o.replace(m[1],t)}return o}});
/*
jQueryTools (http://flowplayer.org/tools/)
*/
(function(a){function t(d,b){var c=this,j=d.add(c),o=a(window),k,f,m,g=a.tools.expose&&(b.mask||b.expose),n=Math.random().toString().slice(10);if(g){if(typeof g=="string"){g={color:g}}g.closeOnClick=g.closeOnEsc=false}var p=b.target||d.attr("rel");f=p?a(p):d;if(!f.length){throw"Could not find Overlay: "+p}d&&d.index(f)==-1&&d.click(function(e){c.load(e);return e.preventDefault()});a.extend(c,{load:function(e){if(c.isOpened()){return c}var h=q[b.effect];if(!h){throw'Overlay: cannot find effect : "'+b.effect+'"'}b.oneInstance&&a.each(s,function(){this.close(e)});e=e||a.Event();e.type="onBeforeLoad";j.trigger(e);if(e.isDefaultPrevented()){return c}m=true;g&&a(f).expose(g);var i=b.top,r=b.left,u=f.outerWidth({margin:true}),v=f.outerHeight({margin:true});if(typeof i=="string"){i=i=="center"?Math.max((o.height()-v)/2,0):parseInt(i,10)/100*o.height()}if(r=="center"){r=Math.max((o.width()-u)/2,0)}h[0].call(c,{top:i,left:r},function(){if(m){e.type="onLoad";j.trigger(e)}});g&&b.closeOnClick&&a.mask.getMask().one("click",c.close);b.closeOnClick&&a(document).bind("click."+n,function(l){a(l.target).parents(f).length||c.close(l)});b.closeOnEsc&&a(document).bind("keydown."+n,function(l){l.keyCode==27&&c.close(l)});return c},close:function(e){if(!c.isOpened()){return c}e=e||a.Event();e.type="onBeforeClose";j.trigger(e);if(!e.isDefaultPrevented()){m=false;q[b.effect][1].call(c,function(){e.type="onClose";j.trigger(e)});a(document).unbind("click."+n).unbind("keydown."+n);g&&a.mask.close();return c}},getOverlay:function(){return f},getTrigger:function(){return d},getClosers:function(){return k},isOpened:function(){return m},getConf:function(){return b}});a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(e,h){a.isFunction(b[h])&&a(c).bind(h,b[h]);c[h]=function(i){i&&a(c).bind(h,i);return c}});k=f.find(b.close||".close");if(!k.length&&!b.close){k=a('<a class="close"></a>');f.prepend(k)}k.click(function(e){c.close(e)});b.load&&c.load()}a.tools=a.tools||{version:"1.2.5"};a.tools.overlay={addEffect:function(d,b,c){q[d]=[b,c]},conf:{close:null,closeOnClick:true,closeOnEsc:true,closeSpeed:"fast",effect:"default",fixed:!a.browser.msie||a.browser.version>6,left:"center",load:false,mask:null,oneInstance:true,speed:"normal",target:null,top:"10%"}};var s=[],q={};a.tools.overlay.addEffect("default",function(d,b){var c=this.getConf(),j=a(window);if(!c.fixed){d.top+=j.scrollTop();d.left+=j.scrollLeft()}d.position=c.fixed?"fixed":"absolute";this.getOverlay().css(d).fadeIn(c.speed,b)},function(d){this.getOverlay().fadeOut(this.getConf().closeSpeed,d)});a.fn.overlay=function(d){var b=this.data("overlay");if(b){return b}if(a.isFunction(d)){d={onBeforeLoad:d}}d=a.extend(true,{},a.tools.overlay.conf,d);this.each(function(){b=new t(a(this),d);s.push(b);a(this).data("overlay",b)});return d.api?b:this}})(jQuery);(function(b){function k(){if(b.browser.msie){var a=b(document).height(),d=b(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,a-d<20?d:a]}return[b(document).width(),b(document).height()]}function h(a){if(a){return a.call(b.mask)}}b.tools=b.tools||{version:"1.2.5"};var l;l=b.tools.expose={conf:{maskId:"exposeMask",loadSpeed:"slow",closeSpeed:"fast",closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,startOpacity:0,color:"#fff",onLoad:null,onClose:null}};var c,i,e,g,j;b.mask={load:function(a,d){if(e){return this}if(typeof a=="string"){a={color:a}}a=a||g;g=a=b.extend(b.extend({},l.conf),a);c=b("#"+a.maskId);if(!c.length){c=b("<div/>").attr("id",a.maskId);b("body").append(c)}var m=k();c.css({position:"absolute",top:0,left:0,width:m[0],height:m[1],display:"none",opacity:a.startOpacity,zIndex:a.zIndex});a.color&&c.css("backgroundColor",a.color);if(h(a.onBeforeLoad)===false){return this}a.closeOnEsc&&b(document).bind("keydown.mask",function(f){f.keyCode==27&&b.mask.close(f)});a.closeOnClick&&c.bind("click.mask",function(f){b.mask.close(f)});b(window).bind("resize.mask",function(){b.mask.fit()});if(d&&d.length){j=d.eq(0).css("zIndex");b.each(d,function(){var f=b(this);/relative|absolute|fixed/i.test(f.css("position"))||f.css("position","relative")});i=d.css({zIndex:Math.max(a.zIndex+1,j=="auto"?0:j)})}c.css({display:"block"}).fadeTo(a.loadSpeed,a.opacity,function(){b.mask.fit();h(a.onLoad);e="full"});e=true;return this},close:function(){if(e){if(h(g.onBeforeClose)===false){return this}c.fadeOut(g.closeSpeed,function(){h(g.onClose);i&&i.css({zIndex:j});e=false});b(document).unbind("keydown.mask");c.unbind("click.mask");b(window).unbind("resize.mask")}return this},fit:function(){if(e){var a=k();c.css({width:a[0],height:a[1]})}},getMask:function(){return c},isLoaded:function(a){return a?e=="full":e},getConf:function(){return g},getExposed:function(){return i}};b.fn.mask=function(a){b.mask.load(a);return this};b.fn.expose=function(a){b.mask.load(a,this);return this}})(jQuery);var JSON;if(!JSON){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());var CabalonFilter=function(selector,maxDisplayOnInit){var filter={usedSelector:selector,$selector:$(selector),maxDisplay:maxDisplayOnInit,showFilterExtra:function(element){for(i=0;i<el.length;i++){list=($(el[i]).find("li"));for(n=maxDisplayOnInit;n<list.length;n++){($(list[n]).toggleClass("hide"))}}},onSelectFilter:function(event,element){$element=$(element);$element.toggleClass("selectedFilter");$element.trigger("selectFilterEvent",element);$element.trigger("afterFilterStatusChangedEvent",element)},onUnselectFilter:function(event,element){$element=$(element);$element.toggleClass("selectedFilter");$element.trigger("unselectFilterEvent",element);$element.trigger("afterFilterStatusChangedEvent",element)},clickFilter:function(element){$(element).trigger("beforeFilterStatusChangedEvent",element)},hideRemainingFilter:function(){el=filter.$selector;for(i=0;i<el.length;i++){list=($(el[i]).find("li"));for(n=maxDisplayOnInit;n<list.length;n++){if(!$(list[n]).hasClass("hide")){($(list[n]).toggleClass("hide"))}}}},init:function(){filter.hideRemainingFilter();filter.$selector.delegate(".more","click",function(event){el=$(this).parent();el.trigger("onShowFilterExtraEvent",{element:el,filterInstance:filter})});$(document).bind("onShowFilterExtraEvent",function(event,element){filter.showFilterExtra(element)});filter.$selector.delegate("li a","click",function(event){$(this).trigger("filterClickedEvent",{element:this,filterInstance:filter})});filter.$selector.live("filterClickedEvent",function(event,data){event.preventDefault();element=data.element;filter.clickFilter(element)});filter.$selector.live("beforeFilterStatusChangedEvent",function(event,element){if(!$(element).hasClass("selectedFilter")){filter.onSelectFilter(event,element)}else{filter.onUnselectFilter(event,element)}})},reinit:function(){filter.$selector=$(filter.usedSelector);filter.$selector.undelegate(".more","click");$(document).unbind("onShowFilterExtraEvent");filter.$selector.undelegate("li a","click");filter.$selector.die("filterClickedEvent");filter.$selector.die("beforeFilterStatusChangedEvent");filter.init()}};return filter};var CabalonClient=function(){var client={stock:[],baseURL:"",getBaseUrl:function(url){if(url){splitted=url.split("?");baseUrl=splitted[0];return baseUrl}else{return""}},getUrlVarString:function(urlVars){paramsString="";for(i=0;i<urlVars.length;i++){if(urlVars[urlVars[i]] instanceof Array){params=urlVars[urlVars[i]];paramsString+=params.join("&"+urlVars[i]+"=")}else{if(urlVars[urlVars[i]]){paramsString+=("&"+urlVars[i]+"="+urlVars[urlVars[i]])}}}return paramsString},getUrlVars:function(url,getHash){var vars=[],hash;if(!getHash||getHash==false){url=url.split("#")[0]}else{url=url.split("#");if(url.length>1){url=url[1]}}if(url.indexOf("?")>0){var hashes=url.slice(url.indexOf("?")+1).split("&");for(var i=0;i<hashes.length;i++){hash=hashes[i].split("=");offset=hash[0].indexOf("[]");if(offset>0&&offset==hash[0].length-2){hash[0]=hash[0].substring(0,hash[0].length-2)}vars.push(hash[0]);if(!vars[hash[0]]){vars[hash[0]]=hash[1]}else{if(!(vars[hash[0]] instanceof Array)){v=vars[hash[0]];vars[hash[0]]=[];vars[hash[0]].push(v);vars[hash[0]].push(hash[1])}else{vars[hash[0]].push(hash[1])}}}vars=$.unique(vars)}return vars},isInArray:function(needle,haystack){if(typeof haystack!="undefined"&&haystack!=null&&typeof needle!="undefined"&&needle!=null){if(needle instanceof Array){count=0;for(k=0;k<haystack.length;k++){if(haystack[k]==needle[count]){return true}count++;if(count>=needle.length){return false}}return false}else{for(k=0;k<haystack.length;k++){if(haystack[k]==needle){return true}}}return false}else{return false}},getRequestParams:function(selector,blackList,url){selectedFilter=$(selector);client.stock=[];tempStock=[];cabaFilterStock=[];otherParams=[];for(i=0;i<selectedFilter.length;i++){f=selectedFilter[i];tempStock.push(f.href)}if(url){tempStock.push(url)}for(i=0;i<tempStock.length;i++){urlVars=client.getUrlVars(tempStock[i]);if(urlVars.cabaFilter){cabaFilterStock[cabaFilterStock.length]=JSON.parse($.URLDecode(urlVars.cabaFilter))[0]}for(n=0;n<urlVars.length;n++){if(urlVars[n]!="cabaFilter"&&urlVars[n]!=""&&urlVars[n]!="ajax"){if(typeof otherParams[urlVars[n]]=="undefined"&&otherParams[urlVars[n]]==null&&!client.isInArray(urlVars[n],blackList)){otherParams.push(urlVars[n]);otherParams[urlVars[n]]=urlVars[urlVars[n]]}}}}baseUrl=client.getBaseUrl(tempStock[tempStock.length-1]);otherParams=$.unique(otherParams);return{cabaFilterParams:cabaFilterStock,baseUrl:baseUrl,otherParams:otherParams}},getRequestUrl:function(data,resultSelector){cabaParams=data.cabaFilterParams;baseUrl=data.baseUrl;otherParams=data.otherParams;otherParamsString=client.getUrlVarString(otherParams);if(cabaParams.length>0&&cabaParams!=""){json=JSON.stringify(cabaParams);if(resultSelector){return baseUrl+"?ajax=true"+otherParamsString+"&cabaFilter="+$.URLEncode(json)+" "+resultSelector}else{return baseUrl+"?ajax=true"+otherParamsString+"&cabaFilter="+$.URLEncode(json)}}else{if(resultSelector){return baseUrl+"?ajax=true"+otherParamsString+" "+resultSelector}else{return baseUrl+"?ajax=true"+otherParamsString}}}};return client};var CabaFilterOverlayEffect=function(data){element=data.element;$("#overlay_filter").overlay({mask:{color:"#ebecff",loadSpeed:250,opacity:0.9},closeOnClick:false});$(".overlayFilterBoxContent").html($($(element).find(".filterList")[0]).clone().wrap("<div></div>").parent().html());$(".overlayFilterBoxContent").find(".filterList").toggleClass("overlayedFilterList");list=$("#overlay_filter").find("li");for(n=0;n<list.length;n++){if(($(list[n]).hasClass("hide"))){($(list[n]).toggleClass("hide"))}}$("#overlay_filter").overlay().load();$("#overlay_filter").css("top",window.outerHeight*0.2);$("#overlay_filter").css("left",($(element).position().left+20));$("#overlay_filter").undelegate(".overlayedFilterList a","click");$("#overlay_filter").undelegate(".applyFilter ","click");$("#overlay_filter").undelegate(".removeAllFilter ","click");$("#overlay_filter").delegate(".overlayedFilterList a","click",function(event){$(this).toggleClass("selectedFilter")});$("#overlay_filter").delegate(".applyFilter ","click",function(event){$(this).trigger("overlayApplyFilterEvent",{overlay:this,source:element})});$("#overlay_filter").delegate(".removeAllFilter ","click",function(event){list=$("#overlay_filter").find("li a");for(n=0;n<list.length;n++){if(($(list[n]).hasClass("selectedFilter"))){($(list[n]).toggleClass("selectedFilter"))}}})};var CabaGetSelectedFiltersAfterOverlayClose=function(data){originalFilter=$(data.source).find("a:.selectedFilter");appliedFilter=$("#overlay_filter a:.selectedFilter");sourceList=$(data.source).find("a");countAppliedFilter=0;for(i=0;i<sourceList.length;i++){isInList=false;for(n=0;n<appliedFilter.length;n++){if(appliedFilter[n].href==sourceList[i].href){isInList=true;break}}if(isInList){if(!$(sourceList[i]).hasClass("selectedFilter")){$(sourceList[i]).toggleClass("selectedFilter");countAppliedFilter++}}else{if($(sourceList[i]).hasClass("selectedFilter")){$(sourceList[i]).toggleClass("selectedFilter");countAppliedFilter++}}}for(n=0;n<appliedFilter.length;n++){$(appliedFilter[n]).removeClass("selectedFilter")}return countAppliedFilter};
