/*
 * 
 * TableSorter 2.0 - Client-side table sorting with ease!
 * Version 2.0.1
 * @requires jQuery v1.2.1
 * 
 * Copyright (c) 2007 Christian Bach
 * Examples and docs at: http://tablesorter.com
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 */
eval(function(p,a,c,k,e,d){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--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[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}('(8($){$.1L({L:D 8(){7 C=[],1a=[];k.2z={2e:"45",2F:"3Y",2D:"2W",2d:"2X",2I:"2Y",1S:1t,1s:"2q",C:{},1a:[],1p:{Y:["2y","2O"]},x:{},2l:K,2N:Z,u:[],1D:[],1m:"2R",I:K};8 19(s,d){1l(s+","+(D X().1f()-d.1f())+"2Z")}k.19=19;8 1l(s){q(1B 1R!="24"&&1B 1R.I!="24"){1R.1l(s)}M{30(s)}}8 1T(6,$x){q(6.f.I){7 1P=""}7 F=6.J[0].F;q(6.J[0].F[0]){7 13=[],14=F[0].14,l=14.w;y(7 i=0;i<l;i++){7 p=K;q($.1q&&($($x[i]).17()&&$($x[i]).17().1e)){p=1O($($x[i]).17().1e)}M q((6.f.x[i]&&6.f.x[i].1e)){p=1O(6.f.x[i].1e)}q(!p){p=2p(6.f,14[i])}q(6.f.I){1P+="1I:"+i+" 1G:"+p.B+"\\n"}13.R(p)}}q(6.f.I){1l(1P)}m 13};8 2p(f,V){7 l=C.w;y(7 i=1;i<l;i++){q(C[i].Q($.1Q(1N(f,V)))){m C[i]}}m C[0]}8 1O(1w){7 l=C.w;y(7 i=0;i<l;i++){q(C[i].B.15()==1w.15()){m C[i]}}m K}8 1U(6){q(6.f.I){7 28=D X()}7 1b=(6.J[0]&&6.J[0].F.w)||0,26=(6.J[0].F[0]&&6.J[0].F[0].14.w)||0,C=6.f.C,G={W:[],1n:[]};y(7 i=0;i<1b;++i){7 c=6.J[0].F[i],1h=[];G.W.R($(c));y(7 j=0;j<26;++j){1h.R(C[j].H(1N(6.f,c.14[j]),6,c.14[j]))}1h.R(i);G.1n.R(1h);1h=1t};q(6.f.I){19("31 G y "+1b+" F:",28)}m G};8 1N(f,V){q(!V)m"";7 t="";q(f.1s=="2q"){q(V.1X[0]&&V.1X[0].3j()){t=V.1X[0].23}M{t=V.23}}M{q(1B(f.1s)=="8"){t=f.1s(V)}M{t=$(V).1k()}}m t}8 1H(6,G){q(6.f.I){7 2c=D X()}7 c=G,r=c.W,n=c.1n,1b=n.w,1K=(n[0].w-1),2g=$(6.J[0]),F=[];y(7 i=0;i<1b;i++){F.R(r[n[i][1K]]);q(!6.f.21){7 o=r[n[i][1K]];7 l=o.w;y(7 j=0;j<l;j++){2g[0].3u(o[j])}}}q(6.f.21){6.f.21(6,F)}F=1t;q(6.f.I){19("38 6:",2c)}1F(6)};8 2a(6){q(6.f.I){7 1g=D X()}7 1q=($.1q)?Z:K,1W=[];y(7 i=0;i<6.1i.F.w;i++){1W[i]=0};$1E=$(1V(6,1W,0,6.1i.F[0].14.w));$1E.1x(8(1u){k.1c=0;k.1I=1u;k.18=2k(6.f.2d);q(2C(k)||2i(6,1u))k.1C=Z;q(!k.1C){$(k).1y(6.f.2e)}6.f.1D[1u]=k});q(6.f.I){19("3c x:",1g);1l($1E)}m $1E};8 1V(6,1r,W){7 1j=[],r=6.1i.F,c=r[W].14;y(7 i=1r[W];i<c.w;i++){7 S=c[i];q(S.3d>1){1j=1j.3e(1V(6,1r,W+S.2h))}M{q(6.1i.w==1||(S.2h>1||!r[W+1])){1j.R(S)}1r[W]=(i+W)}}m 1j};8 2C(S){q(($.1q)&&($(S).17().1e===K)){m Z};m K}8 2i(6,i){q((6.f.x[i])&&(6.f.x[i].1e===K)){m Z};m K}8 1F(6){7 c=6.f.1a;7 l=c.w;y(7 i=0;i<l;i++){22(c[i]).H(6)}}8 22(1w){7 l=1a.w;y(7 i=0;i<l;i++){q(1a[i].B.15()==1w.15()){m 1a[i]}}};8 2k(v){q(1B(v)!="3k"){i=(v.15()=="3l")?1:0}M{i=(v==(0||1))?v:0}m i}8 2V(v,a){7 l=a.w;y(7 i=0;i<l;i++){q(a[i][0]==v){m Z}}m K}8 1Y(6,$x,13,Y){$x.1A(Y[0]).1A(Y[1]);7 h=[];$x.1x(8(3m){q(!k.1C){h[k.1I]=$(k)}});7 l=13.w;y(7 i=0;i<l;i++){h[13[i][0]].1y(Y[13[i][1]])}}8 2G(6,$x){7 c=6.f;q(c.2l){7 1z=$(\'<1z>\');$("2o:3D 3C",6.J[0]).1x(8(){1z.3q($(\'<3r>\').Y(\'2n\',$(k).2n()))});$(6).3s(1z)}}8 2Q(6,u){7 c=6.f,l=u.w;y(7 i=0;i<l;i++){7 s=u[i],o=c.1D[s[0]];o.1c=s[1];o.1c++}}8 20(6,u,G){q(6.f.I){7 2s=D X()}7 12="7 2r = 8(a,b) {",l=u.w;y(7 i=0;i<l;i++){7 c=u[i][0];7 18=u[i][1];7 s=(2x(6.f.C,c)=="1k")?((18==0)?"2t":"2u"):((18==0)?"2v":"2w");7 e="e"+i;12+="7 "+e+" = "+s+"(a["+c+"],b["+c+"]); ";12+="q("+e+") { m "+e+"; } ";12+="M { "}7 1J=G.1n[0].w-1;12+="m a["+1J+"]-b["+1J+"];";y(7 i=0;i<l;i++){12+="}; "}12+="m 0; ";12+="}; ";3v(12);G.1n.3x(2r);q(6.f.I){19("3y 3A "+u.3B()+" 3F 3G "+18+" 1g:",2s)}m G};8 2t(a,b){m((a<b)?-1:((a>b)?1:0))};8 2u(a,b){m((b<a)?-1:((b>a)?1:0))};8 2v(a,b){m a-b};8 2w(a,b){m b-a};8 2x(C,i){m C[i].O};k.2j=8(2A){m k.1x(8(){7 $k,$3J,$x,G,f,3K=0,3L;k.f={};f=$.1L(k.f,$.L.2z,2A);q(!k.1i||!k.J)m Z;$k=$(k);$x=2a(k);k.f.C=1T(k,$x);G=1U(k);7 1Z=[f.2D,f.2F];2G(k);$x.3P(8(e){7 1b=($k[0].J[0]&&$k[0].J[0].F.w)||0;q(!k.1C&&1b>0){7 $S=$(k);7 i=k.1I;k.18=k.1c++%2;q(!e[f.2I]){f.u=[];q(f.1S!=1t){7 a=f.1S;y(7 j=0;j<a.w;j++){f.u.R(a[j])}}f.u.R([i,k.18])}M{q(2V(i,f.u)){y(7 j=0;j<f.u.w;j++){7 s=f.u[j],o=f.1D[s[0]];q(s[0]==i){o.1c=s[1];o.1c++;s[1]=o.1c%2}}}M{f.u.R([i,k.18])}};1Y($k[0],$x,f.u,1Z);1H($k[0],20($k[0],f.u,G));m K}}).3U(8(){q(f.2N){k.3V=8(){m K};m K}});$k.1o("3W",8(){k.f.C=1T(k,$x);G=1U(k)}).1o("2K",8(e,13){f.u=13;7 u=f.u;2Q(k,u);1Y(k,$x,u,1Z);1H(k,20(k,u,G))}).1o("41",8(){1H(k,G)}).1o("42",8(e,B){22(B).H(k)}).1o("44",8(){1F(k)});q($.1q&&($(k).17()&&$(k).17().2S)){f.u=$(k).17().2S}q(f.u.w>0){$k.46("2K",[f.u])}1F(k)})};k.P=8(1G){7 l=C.w,a=Z;y(7 i=0;i<l;i++){q(C[i].B.15()==1G.B.15()){a=K}}q(a){C.R(1G)}};k.2T=8(1M){1a.R(1M)};k.T=8(s){7 i=32(s);m(29(i))?0:i};k.34=8(s){7 i=35(s);m(29(i))?0:i};k.36=8(6){q($.37.39){8 2P(){3a(k.2f)k.3b(k.2f)}2P.3f(6.J[0])}M{6.J[0].23=""}}}});$.3h.1L({L:$.L.2j});7 N=$.L;N.P({B:"1k",Q:8(s){m Z},H:8(s){m $.1Q(s.15())},O:"1k"});N.P({B:"3H",Q:8(s){m/^\\d+$/.16(s)},H:8(s){m $.L.T(s)},O:"U"});N.P({B:"3n",Q:8(s){m/^[£$€?.]/.16(s)},H:8(s){m $.L.T(s.11(D 1d(/[^0-9.]/g),""))},O:"U"});N.P({B:"3p",Q:8(s){m s.2J(D 1d(/^(\\+|-)?[0-9]+\\.[0-9]+((E|e)(\\+|-)?[0-9]+)?$/))},H:8(s){m $.L.T(s.11(D 1d(/,/),""))},O:"U"});N.P({B:"3t",Q:8(s){m/^\\d{2,3}[\\.]\\d{2,3}[\\.]\\d{2,3}[\\.]\\d{2,3}$/.16(s)},H:8(s){7 a=s.3w("."),r="",l=a.w;y(7 i=0;i<l;i++){7 1v=a[i];q(1v.w==2){r+="0"+1v}M{r+=1v}}m $.L.T(r)},O:"U"});N.P({B:"3I",Q:8(s){m/^(2b?|2B|2E):\\/\\/$/.16(s)},H:8(s){m 2U.1Q(s.11(D 1d(/(2b?|2B|2E):\\/\\//),\'\'))},O:"1k"});N.P({B:"3Q",Q:8(s){m/^\\d{4}[\\/-]\\d{1,2}[\\/-]\\d{1,2}$/.16(s)},H:8(s){m $.L.T((s!="")?D X(s.11(D 1d(/-/g),"/")).1f():"0")},O:"U"});N.P({B:"3R",Q:8(s){m/^\\d{1,3}%$/.16(s)},H:8(s){m $.L.T(s.11(D 1d(/%/g),""))},O:"U"});N.P({B:"3S",Q:8(s){m s.2J(D 1d(/^[A-3T-z]{3,10}\\.? [0-9]{1,2}, ([0-9]{4}|\'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\\s(3X|3Z)))$/))},H:8(s){m $.L.T(D X(s).1f())},O:"U"});N.P({B:"40",Q:8(s){m/\\d{1,2}[\\/\\-]\\d{1,2}[\\/\\-]\\d{2,4}/.16(s)},H:8(s,6){7 c=6.f;s=s.11(/\\-/g,"/");q(c.1m=="2R"){s=s.11(/(\\d{1,2})[\\/\\-](\\d{1,2})[\\/\\-](\\d{4})/,"$3/$1/$2")}M q(c.1m=="43"){s=s.11(/(\\d{1,2})[\\/\\-](\\d{1,2})[\\/\\-](\\d{4})/,"$3/$2/$1")}M q(c.1m=="2M/25/27"||c.1m=="2M-25-27"){s=s.11(/(\\d{1,2})[\\/\\-](\\d{1,2})[\\/\\-](\\d{2})/,"$1/$2/$3")}m $.L.T(D X(s).1f())},O:"U"});N.P({B:"1g",Q:8(s){m/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\\s(3g|3i)))$/.16(s)},H:8(s){m $.L.T(D X("3o/2m/2m "+s).1f())},O:"U"});N.P({B:"3E",Q:8(s){m K},H:8(s,6,S){7 c=6.f,p=(!c.2H)?\'3M\':c.2H;m $(S).17()[p]},O:"U"});N.2T({B:"33",H:8(6){q(6.f.I){7 1g=D X()}$("2o:3z",6.J[0]).2L(\':2y\').1A(6.f.1p.Y[1]).1y(6.f.1p.Y[0]).3O().2L(\':2O\').1A(6.f.1p.Y[0]).1y(6.f.1p.Y[1]);q(6.f.I){$.L.19("3N 47 1M",1g)}}})})(2U);',62,256,'||||||table|var|function|||||||config|||||this||return||||if||||sortList||length|headers|for|||id|parsers|new||rows|cache|format|debug|tBodies|false|tablesorter|else|ts|type|addParser|is|push|cell|formatFloat|numeric|node|row|Date|css|true||replace|dynamicExp|list|cells|toLowerCase|test|data|order|benchmark|widgets|totalRows|count|RegExp|sorter|getTime|time|cols|tHead|arr|text|log|dateFormat|normalized|bind|widgetZebra|meta|headerArr|textExtraction|null|index|item|name|each|addClass|colgroup|removeClass|typeof|sortDisabled|headerList|tableHeaders|applyWidget|parser|appendToTable|column|orgOrderCol|checkCell|extend|widget|getElementText|getParserById|parsersDebug|trim|console|sortForce|buildParserCache|buildCache|checkCellColSpan|tableHeadersRows|childNodes|setHeadersCss|sortCSS|multisort|appender|getWidgetById|innerHTML|undefined|mm|totalCells|yy|cacheTime|isNaN|buildHeaders|https|appendTime|sortInitialOrder|cssHeader|firstChild|tableBody|rowSpan|checkHeaderOptions|construct|formatSortingOrder|widthFixed|01|width|tr|detectParserForColumn|simple|sortWrapper|sortTime|sortText|sortTextDesc|sortNumeric|sortNumericDesc|getCachedSortType|even|defaults|settings|ftp|checkHeaderMetadata|cssDesc|file|cssAsc|fixColumnWidth|parserMetadataName|sortMultiSortKey|match|sorton|filter|dd|cancelSelection|odd|empty|updateHeaderSortCount|us|sortlist|addWidget|jQuery|isValueInArray|headerSortDown|asc|shiftKey|ms|alert|Building|parseFloat|zebra|formatInt|parseInt|clearTableBody|browser|Rebuilt|msie|while|removeChild|Built|colSpan|concat|apply|am|fn|pm|hasChildNodes|Number|desc|offset|currency|2000|floating|append|col|prepend|ipAddress|appendChild|eval|split|sort|Sorting|visible|on|toString|td|first|metadata|and|dir|integer|url|document|shiftDown|sortOrder|sortValue|Applying|end|click|isoDate|percent|usLongDate|Za|mousedown|onselectstart|update|AM|headerSortUp|PM|shortDate|appendCache|applyWidgetId|uk|applyWidgets|header|trigger|Zebra'.split('|'),0,{}));



/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || 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.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-06-20 16:24:37 -0500 (Wed, 20 Jun 2007) $
 * $Rev: 2124 $
 *
 * Version: 2.2
 *
 * Apply the mousewheel event to the elements in the jQuery object.
 * The handler function should be prepared to take the event object
 * and a param called 'delta'. The 'delta' param is a number
 * either > 0 or < 0. > 0 = up and < 0 = down.
 *
 * The pageX, pageY, clientX and clientY event properties
 * are fixed in Firefox.
 *
 * @example $("p").mousewheel(function(event, delta){
 *   if (delta > 0)
 *     // do something on mousewheel scroll up
 *   else if (delta < 0)
 *     //do something on mousewheel scroll down
 * });
 *
 * @name mousewheel
 * @type jQuery
 * @param Function handler A function to call when onmousewheel fires. Should take two params: event and delta.
 * @cat Plugins/Mousewheel
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 */
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}('(5($){$.O.H({p:5(f){2(!f.d)f.d=$.6.d++;2(!$.6.j)$.6.j=[];g 1.y(5(){2(1.4)g 1.4.m(f);8 1.4=[];1.4.m(f);c s=1;1.7=5(e){e=$.6.Q(e||o.6);$.H(e,1.n||{});c a=0,u=M;2(e.q)a=e.q/J;2(e.v)a=-e.v/3;2(o.U)a=-e.q;t(c i=0;i<s.4.r;i++)2(s.4[i])2(s.4[i].T(s,e,a)===9){u=9;e.S();e.R()}g u};2($.k.l&&!1.b){1.b=5(e){1.n={G:e.G,E:e.E,C:e.C,D:e.D}};$(1).P(\'B\',1.b)}2(1.h)2($.k.l)1.h(\'A\',1.7,9);8 1.h(\'p\',1.7,9);8 1.z=1.7;$.6.j.m($(1))})},x:5(f){g 1.y(5(){2(f&&1.4){t(c i=0;i<1.4.r;i++)2(1.4[i]&&1.4[i].d==f.d)N 1.4[i]}8{2($.k.l&&!1.b)$(1).L(\'B\',1.b);2(1.h)2($.k.l)1.F(\'A\',1.7,9);8 1.F(\'p\',1.7,9);8 1.z=w;1.4=1.7=1.b=1.n=w}})}});$(o).K(\'I\',5(){c a=$.6.j||[];t(c i=0;i<a.r;i++)a[i].x()})})(V);',58,58,'|this|if||_mwHandlers|function|event|_mwHandler|else|false||_mwFixCursorPos|var|guid|||return|addEventListener||_mwCache|browser|mozilla|push|_mwCursorPos|window|mousewheel|wheelDelta|length||for|returnValue|detail|null|unmousewheel|each|onmousewheel|DOMMouseScroll|mousemove|clientX|clientY|pageY|removeEventListener|pageX|extend|unload|120|one|unbind|true|delete|fn|bind|fix|stopPropagation|preventDefault|call|opera|jQuery'.split('|'),0,{}))



/*
 * jQuery Easing v1.1 - http://gsgd.co.uk/sandbox/jquery.easing.php
 *
 * Uses the built in easing capabilities added in jQuery 1.1
 * to offer multiple easing options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */

jQuery.easing = {
	easein: function(x, t, b, c, d) {
		return c*(t/=d)*t + b; // in
	},
	easeinout: function(x, t, b, c, d) {
		if (t < d/2) return 2*c*t*t/(d*d) + b;
		var ts = t - d/2;
		return -2*c*ts*ts/(d*d) + 2*c*ts/d + c/2 + b;		
	},
	easeout: function(x, t, b, c, d) {
		return -c*t*t/(d*d) + 2*c*t/d + b;
	},
	expoin: function(x, t, b, c, d) {
		var flip = 1;
		if (c < 0) {
			flip *= -1;
			c *= -1;
		}
		return flip * (Math.exp(Math.log(c)/d * t)) + b;		
	},
	expoout: function(x, t, b, c, d) {
		var flip = 1;
		if (c < 0) {
			flip *= -1;
			c *= -1;
		}
		return flip * (-Math.exp(-Math.log(c)/d * (t-d)) + c + 1) + b;
	},
	expoinout: function(x, t, b, c, d) {
		var flip = 1;
		if (c < 0) {
			flip *= -1;
			c *= -1;
		}
		if (t < d/2) return flip * (Math.exp(Math.log(c/2)/(d/2) * t)) + b;
		return flip * (-Math.exp(-2*Math.log(c/2)/d * (t-d)) + c + 1) + b;
	},
	bouncein: function(x, t, b, c, d) {
		return c - jQuery.easing['bounceout'](x, d-t, 0, c, d) + b;
	},
	bounceout: function(x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	bounceinout: function(x, t, b, c, d) {
		if (t < d/2) return jQuery.easing['bouncein'] (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing['bounceout'] (x, t*2-d,0, c, d) * .5 + c*.5 + b;
	},
	elasin: function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	elasout: function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	elasinout: function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	backin: function(x, t, b, c, d) {
		var s=1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	backout: function(x, t, b, c, d) {
		var s=1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	backinout: function(x, t, b, c, d) {
		var s=1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	linear: function(x, t, b, c, d) {
		return c*t/d + b; //linear
	}
};



/*
 *Tooltip
 */
(function($) {
	$.fn.tooltip = function() {		
	    return this.each(function() {
			
			// create a random id for the link
			if(!$(this).attr("id")) {
				$(this).attr("id", "rand" + Math.round(Math.random() * 10000));
			}
			
			$(this).unbind('hover');
			$(this).unbind('click');			
			
			// add event listeners
			$(this)
			.hover(function() {
				add($(this).attr("href"), $(this).attr("id"), $(this).attr("title"));
			},function(){
				remove();
			})
			.click(function() {
				return false;
			});
			
		});
	};
	
	function add(url,linkId, title){
		if(title == undefined) title = "&nbsp;";
		title="&nbsp;";
		var de = document.documentElement;
		var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var hasArea = w - getAbsoluteLeft(linkId);
		var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
		
		var queryString = url.replace(/^[^\?]+\??/,'');
		var params = parseQuery( queryString );
		if(params['width'] === undefined){params['width'] = 155};
		if(params['link'] !== undefined){
			$('#' + linkId).bind('click',function(){window.location = params['link']});
			$('#' + linkId).css('cursor','pointer');
		}
		
		if(hasArea>((params['width']*1)+75)){
			$("body").append("<div id='tooltip'><div id='tooltip_close_left'>"+title+"</div><div id='tooltip_holder'><div class='loader'><div></div></div>");//right side
			var arrowOffset = getElementWidth(linkId) + 11;
			var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
		}
		else{
			$("body").append("<div id='tooltip'><div id='tooltip_close_right'>"+title+"</div><div id='tooltip_holder'><div class='loader'><div></div></div>");//left side
			var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 15); //set x position
		}
		
		$('#tooltip').css({left: clickElementx+"px", top: clickElementy+"px"}).show();
		$('#tooltip_holder').load(url);

	};
	
	function remove() {
		$('#tooltip').remove();
	};
	
	function getElementWidth(objectId) {
		return document.getElementById(objectId).offsetWidth;
	};

	// Get an object left position from the upper left viewport corner
	function getAbsoluteLeft(objectId) {		
		o = document.getElementById(objectId)
		oLeft = o.offsetLeft            // Get left position from the parent object
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
			oLeft += oParent.offsetLeft // Add parent left position
			o = oParent
		}
		return oLeft
	};

	// Get an object top position from the upper left viewport corner
	function getAbsoluteTop(objectId) {		
		o = document.getElementById(objectId)
		oTop = o.offsetTop            // Get top position from the parent object
		while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent  // Get parent object reference
			oTop += oParent.offsetTop // Add parent top position
			o = oParent
		}
		return oTop
	};

	function parseQuery ( query ) {
	   var Params = new Object ();
	   if ( ! query ) return Params; // return empty object
	   var Pairs = query.split(/[;&]/);
	   for ( var i = 0; i < Pairs.length; i++ ) {
		  var KeyVal = Pairs[i].split('=');
		  if ( ! KeyVal || KeyVal.length != 2 ) continue;
		  var key = unescape( KeyVal[0] );
		  var val = unescape( KeyVal[1] );
		  val = val.replace(/\+/g, ' ');
		  Params[key] = val;
	   }
	   return Params;
	};

})(jQuery);




(function($) {

	$.fn.jCarouselLite = function(o) {   
	    o = $.extend({
	        btnPrev: null,
	        btnNext: null,
	        btnGo: null,
	        mouseWheel: false,
	        auto: null,

	        speed: 200,
	        easing: null,

	        vertical: false,
	        circular: true,
	        visible: 3,
	        start: 0,
	        scroll: 1,

	        beforeStart: null,
	        afterEnd: null
	    }, o || {});

	    return this.each(function() {                           // Returns the element collection. Chainable.
	            
	        var running = false;
			var animCss = (o.vertical) ? "top" : "left";
			var sizeCss = (o.vertical) ? "height" : "width";
	        var div = $(this);
			var ul = $("ul", div);
			//var tLi = $("li", ul);
			var tLi = ul.find("> li");
			var tl = tLi.size();
			var v = o.visible;

	        if(o.circular) {
	            ul.prepend(tLi.gt(tl-v-1).clone()).append(tLi.lt(v).clone());
	            o.start += v;
	        }
	        
	        //var li = $("li", ul);
			var li = ul.find("> li");
			var itemLength = li.size();
			var curr = o.start;                       
	        div.css("visibility", "visible");

	        li.css("overflow", "hidden")                        // If the list item size is bigger than required
	            .css("float", o.vertical ? "none" : "left")     // Horizontal list
	            .children().css("overflow", "hidden");          // If the item within li overflows its size, hide'em

	        ul.css("margin", "0")                               // Browsers apply default margin 
	            .css("padding", "0")                            // and padding. It is reset here.
	            .css("position", "relative")                    // IE BUG - width as min-width
	            .css("z-index", "1");                           // IE doesnt respect width. So z-index smaller than div

	        div.css("overflow", "hidden")                       // Overflows - works in FF
	            .css("position", "absolute")                    // position relative and z-index for IE
	            .css("z-index", "2")                            // more than ul so that div displays on top of ul
	            .css("left", "0px");                            // after creating carousel show it on screen
	                
	        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
	        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
	        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

	        li.css("width", li.width())                         // inner li width. this is the box model width
	            .css("height", li.height());                    // inner li height. this is the box model height

	        ul.css(sizeCss, ulSize+"px")                        // Width of the UL is the full length for all the images
	            .css(animCss, -(curr*liSize));                  // Set the starting item
		
	        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

	        if(o.btnPrev)                 
	            $(o.btnPrev).click(function() { 
	                return go(curr-o.scroll); 
	            });
	        
	        if(o.btnNext)
	            $(o.btnNext).click(function() { 
	                return go(curr+o.scroll); 
	            });

	        if(o.btnGo)
	            $.each(o.btnGo, function(i, val) {
	                $(val).click(function() {
	                    return go(o.circular ? o.visible+i : i);
	                });
	            });

	        if(o.mouseWheel && div.mousewheel)
	            div.mousewheel(function(e, d) { 
	                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
	            });

	        if(o.auto)
	            setInterval(function() { 
	                go(curr+o.scroll); 
	            }, o.auto+o.speed);

	        function vis() {
	            return li.gt(curr-1).lt(v);
	        };  

	        function go(to) {
	            if(!running) {

	                if(o.beforeStart)
	                    o.beforeStart.call(this, vis());

	                if(o.circular) {            // If circular we are in first or last, then goto the other end
	                    if(to<=o.start-v-1) {           // If first, then goto last
	                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");  
	                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements. 
	                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
	                    } else if(to>=itemLength-v+1) { // If last, then goto first
	                        ul.css(animCss, -( (v) * liSize ) + "px" );
	                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements. 
	                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
	                    } else curr = to;
	                } else {                    // If non-circular and to points to first or last, we just return.
	                    if(to<0 || to>itemLength-v) return;
	                    else curr = to;
	                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

	                running = true;

	                ul.animate(
	                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
	                    function() {
	                        if(o.afterEnd)
	                            o.afterEnd.call(this, vis());
	                        running = false;
	                    }
	                );
	                // Disable buttons when the carousel reaches the last/first, and enable when not
	                if(!o.circular) {
	                    $(o.btnPrev + "," + o.btnNext).find("a").removeClass("disabled");
	                    $( (curr-o.scroll<0 && o.btnPrev) 
	                        || 
	                       (curr+o.scroll > itemLength-v && o.btnNext)
	                        ||
	                       []
	                     ).find("a").addClass("disabled");
	                }

	            }
	            return false;
	        };
	    });
	};

	function css(el, prop) {
	    return parseInt($.css(el[0], prop)) || 0;
	};
	function width(el) {
	    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
	};
	function height(el) {
	    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
	};

})(jQuery);



/*
 * Player
 */
 
var PlayerControls = {
	popupWindow: null,
	
	play: function(params) {
		var playertype = "player";
		if (params.indexOf("tone_id") != -1)
		   playertype = "player_ringtone";
		
		if (this.popupWindow) {
			if (params != '') {
                this.popupWindow.document.location.href = url + playertype + params;
			} else {
                this.popupWindow.PopupPlayer.play();
			}
		} else {
			if (params != '') {
                this.popupWindow = window.open(url + playertype + params, "player", "width=165,height=145");
                window.focus();
			} else {
                var trackid  = $("#pdef_trackid").html();
                var wmencpid = $("#pdef_wmencpid").html();
                var artistid = $("#pdef_artistid").html();
				this.popupWindow = window.open(url + playertype + "&trackid="+trackid+"&wmencpid="+wmencpid+"&artistid="+artistid, "player", "width=165,height=145");
	            window.focus();
			}
		}
	},

	reload: function() {
		if (this.popupWindow != null) { 
		if (this.popupWindow.document != null) {		
			this.popupWindow.document.location.reload();
		}
		}
	},

	stop: function() {
		if (this.popupWindow)		
    		this.popupWindow.PopupPlayer.stop();
	},
	
	toggle: function() {
		(PlayerControls.isPlaying()) ? this.stop() : this.play('');
	},
	
	close: function() {
		this.popupWindow.close();
		this.popupWindow = null;
	},
	
	setButtonState: function(playing) {
		if(playing) {
			$("#playstop").attr("title", "Stop");
			$("#playstop img").attr("src", frootdir + "img/yousee/player/design/stop.gif");
            //alert($("#playstop img").attr("src"));
		}
		else {
			$("#playstop").attr("title", "Start");
            		$("#playstop img").attr("src", frootdir + "img/yousee/player/design/play.gif");         
		}
	},
	
	setProgress: function(position, duration) {
		if(!duration) duration = 30;
		
		$("#time").text(PlayerControls.formatTime(position));
		var percent = Math.round(100 / duration * position);
		$("#progress img").setPercent("horizontal", percent, 12, 124);
	},
	
	setVolume: function(percent) {
		if(this.popupWindow) {
			this.popupWindow.PopupPlayer.setVolume(percent);			
		}
		$("#volume img").setPercent("vertical", percent, 17, 59);
	},
	
	isPlaying: function() {
		var isPlaying = false;
		if(this.popupWindow) {
			isPlaying = this.popupWindow.PopupPlayer.isPlaying;
		}
		return isPlaying;
	},
	
	formatTime: function(sec, divider) {
		if(!divider) divider = ":";
		var minutes = PlayerControls.leadingZero(Math.floor(sec/60));
		var seconds = PlayerControls.leadingZero(Math.floor(sec%60));
		return minutes+divider+seconds
	},
	
	upd: function() {
		if (this.popupWindow) {		
			this.popupWindow.initinfo();
		}
	},

	leadingZero: function(num) {
		return (num<10) ? "0"+num : num;
	}
	
};



/*
 *Progressbar
 */
(function($) {
	$.fn.setPercent = function(direction, percent, position, size) {		
	    return this.each(function() {
			
			if(direction == "horizontal") {
				var xPos = position - Math.round((size/100) * (100-percent));
				var xyPos = xPos + "px 0px"; 
			}
			else if(direction == "vertical") {
				var yPos = position - Math.round((size/100) * percent);
				var xyPos = "0px " + yPos + "px";				
			}
			$(this).attr("title", percent+"%").css("background-position", xyPos);
						
		});
	};
})(jQuery);



/*
 * Hitlists
 */
var Hitlists = {
	
	init: function()
	{
		// Add previous and next buttons
		$('<div class="prev"><a class="clickable disabled">' + textStrings.prev + '</a></div>').prependTo('#hitlists');
		$('<div class="next"><a class="clickable">' + textStrings.next + '</a></div>').prependTo('#hitlists');
		
		// Init carousel
		$("#hitlists .block").jCarouselLite({
	        btnNext: ".next",
	        btnPrev: ".prev",
			easing: "easeout",
			speed: 250,
			circular: false,
			mouseWheel: true
	    });
	}
};


/*
 * Newsletter
 */
var Newsletter = {

	init: function()
	{
		var newsletterText = $("#newsletter label").hide().text();
		$("#newsletter input.text")
			.focus(function() {
				if($(this).val() == newsletterText) $(this).val("");
			})
			.blur(function() {
				if($(this).val() == "") $(this).val(newsletterText);
			}
		)
		.val(newsletterText);
	}
};



/*
 * Login
 */
var Login = {

	init: function()
	{
		var usernameText = $("#username_label").hide().text();
		$("#username").val(usernameText).focus(function(){
			if($(this).val() == usernameText) $(this).val("");
		}).blur(function(){
			if($(this).val() == "") $(this).val(usernameText);
		}).val(usernameText);

		var passwordText = $("#password_label").hide().text();
		$("#password").val("").focus(function(){
			if($(this).val() == passwordText) $(this).val("");
		}).blur(function(){
			if($(this).val() == "") $(this).val("");
		}).val("");
		
		/* Login show/hide */
		$("#login .toggle").click(function(){
			$(this).toggleClass("expanded")
			.attr("title", $(this).is(".expanded") ? textStrings.collapse : textStrings.expand)
			.next(".toggleable").slideToggle("fast");
			return false;
		}).attr("title", textStrings.expand);
	}

};



/*
 * Video player
 */
var VideoPlayer = {
	
	$player: null,
	playing: false,
	
	init: function()
	{
		if(!$("#videoplayer").size()) {
			return false;
		}

		//$("#modalOverlay").fadeTo(0, 0);
		//$("#videoplayer").fadeTo(0, 0);
		
		this.$player = $("#videoplayer");
		
		// attach videoplayer button events
		$("#videoplayer .playstop").click(function() {
			VideoPlayer.toggle();
			return false;
		});
		
		$("#videoplayer .fullscreen").click(function() {
			VideoPlayer.fullscreen();
			return false;
		});
		
		$("#videoplayer .basket").click(function() {
            var bask = $(this).parent().parent().find("a.pointer");
			bask.click();
//			alert($(this).attr("href"));
		});
		
		$("#videoplayer .modalClose").click(function() {
			VideoPlayer.close();
		});
		
		$("#videoplayer .volume img").addClass("clickable").click(function(e) {
			var yPos = e.layerY;
			if(!yPos) yPos = e.offsetY;
			yPos = Math.max(14, yPos);
			yPos = Math.min(57, yPos);
			yPos -= 14;
			var percent = 100 - Math.round(100 / 43  * yPos);
			VideoPlayer.setVolume(percent);
			return false;
		});
		
		VideoPlayer.setVolume(50);
		
		
		// attach click events for all video play buttons
		$(".video .play").click(function(e) {
			$parent = $(this).parent().parent();
			
			var video = $(this).attr("href");			
			var artist = $parent.find(".artist").text();
			var track = $parent.find(".title").text();
			var price = $parent.find(".price").text();
			var bask = $parent.find("a.pointer");
//			alert($parent.find("img.jcurs").attr("click"));
			window.scrollTo(0,0);
			PlayerControls.stop();
			VideoPlayer.show(video, artist, track, price, bask);
			
			/*
			VideoPlayer.$player.modal({
				close: false,
				overlayId: 'modalOverlay',
				containerId: 'modalContainer',
				iframeId: 'modalIframe',
				onOpen: VideoPlayer.open,
				onShow: VideoPlayer.show(video, artist, track, price),
				onClose: VideoPlayer.close
			});
			*/
			
			return false;
		});
	},
	
	show: function (video, artist, track, price, bask)
	{
		$("#modalOverlay").show().fadeTo("normal", 0.5, function () {
			$("#videoplayer").show().fadeTo("normal", 1, function () {
				VideoPlayer.openVideo(video);
			});
		});
	
		$("#videoplayer .videoinfo").html('<strong>' + artist + '</strong> ' + track + ' <span>' + price + '</span>');
// 		$("#videoplayer a.basket").attr("click", "alert('test')");
// 		$("#videoplayer a.basket").attr("href", "http://www.google.com");
	},
	
	close: function (dialog) {
		dialog.content.fadeOut(200, function () {
			dialog.container.fadeOut(200, function () {
				dialog.overlay.fadeOut(200, function () {
					$.modal.remove(dialog);
				});
			});
		});
	},
	
	setProgress: function() {
		try {
			var controls = document.tdcvideoplayer.controls;
			var media = document.tdcvideoplayer.currentMedia;
			var position = controls.currentPosition;
			var duration = media.duration;			
			if(!duration) duration = 30;

			$("#videoplayer .time").text(VideoPlayer.formatTime(position));
			var percent = Math.round(100 / duration * position);
			$("#videoplayer .progress img").setPercent("horizontal", percent, 12, 268);
		}
		catch(error) {
			clearInterval(this.itv);
		}
	},
	
	setButtonState: function(playing) {
		if(playing) {
			$("#videoplayer .playstop").addClass("playing").attr("title", "Stop").text("Stop");			
		}
		else {
			$("#videoplayer .playstop").removeClass("playing").attr("title", "Start").text("start");
		}
	},
	
	openVideo: function(url)
	{
		$("#videoplayer .preloader").show();
		document.tdcvideoplayer.url = url;
		clearInterval(VideoPlayer.itv);
		VideoPlayer.itv = setInterval(VideoPlayer.setProgress, 100);
		VideoPlayer.play();
	},
	
	fullscreen: function() {
		document.tdcvideoplayer.fullScreen = true;
	},
	
	toggle: function() {
		(this.isPlaying) ? this.pause() : this.play();
	},
	
	play: function() {
		if(document.tdcvideoplayer.controls) {
			this.isPlaying = true;
			document.tdcvideoplayer.controls.play();
			this.setButtonState(this.isPlaying);
		}
	},
	
	stop: function() {
		if(document.tdcvideoplayer.controls) {
			this.isPlaying = false;
			document.tdcvideoplayer.controls.stop();
			this.setButtonState(this.isPlaying);
		}
	},
	
	pause: function() {
		if(document.tdcvideoplayer) {
			this.isPlaying = false;
			document.tdcvideoplayer.controls.pause();
			this.setButtonState(this.isPlaying);
		}
	},
	
	setVolume: function(percent) {
		if(document.tdcvideoplayer.settings) {
			document.tdcvideoplayer.settings.volume = percent;
			$("#videoplayer .volume img").setPercent("vertical", percent, 14, 43);
		}		
	},
	
	close: function() {		
		clearInterval(this.itv);
		VideoPlayer.stop();
		$("#videoplayer .preloader").hide();
		document.tdcvideoplayer.url = "";
		
		$("#videoplayer").fadeOut("normal", function () {
			$(this).hide();
			$("#modalOverlay").fadeOut("normal", function () {
				$(this).hide();
			});
		});
	},

	formatTime: function(sec, divider) {
		if(!divider) divider = ":";
		var minutes = VideoPlayer.leadingZero(Math.floor(sec/60));
		var seconds = VideoPlayer.leadingZero(Math.floor(sec%60));
		return minutes+divider+seconds
	},
	
	leadingZero: function(num) {
		return (num<10) ? "0"+num : num;
	}
	
};



/*
 * Playlist
 */
var Playlist = {
	
	init: function()
	{		
		$("#playlist .toggle")
			.click(function() {
				Playlist.toggle();
				return false;
			}
		)
		.attr("title", textStrings.expand);
	},
	
	toggle: function(expand)
	{
		if(expand == undefined) {
			Playlist.toggle(!$("#playlist .toggle").is(".expanded"));
		}
		else if(expand == true) {
			$("#playlist .toggle")
				.addClass("expanded")
				.attr("title", textStrings.collapse)
				.next(".toggleable")
				.slideDown("fast");
				createCookie("pexpand","true","");
		}
		else if(expand == false) {
			$("#playlist .toggle")
				.removeClass("expanded")
				.attr("title", textStrings.expand)
				.next(".toggleable")
				.slideUp("fast");
				createCookie("pexpand","false","");
		}
	}
	
};



/*
 * Ringtones popup - changed by Wizkids
 */
var Ringtones = {
	
	$activeRingtoneForm: null,
	$activeRingtoneParent: null,
	
	close: function()
	{
		if(Ringtones.$activeRingtoneForm)
		{
			Ringtones.$activeRingtoneForm.remove();		
			Ringtones.$activeRingtoneParent.removeClass('cloned');
		}
	},
	
	init: function()
	{
		// show/hide inputfield text om blur/focus
		$(".ringtone-terms label").each(function() {
			var labelText = $(this).hide().text();
			$(this).next("input.text").val(labelText);
			/*$(this).next("input.text").val(labelText).focus(function(){
				if($(this).val() == labelText) $(this).val("");
			}).blur(function(){
				if($(this).val() == "") $(this).val(labelText);
			}).val(labelText);
			*/
		});
	
		// "popup" for all ringtone terms
		$(".ringtone-terms")
		.hide()
		.each(function() {		
			// attach click event for all ringtone buy buttons
			$(this).parent().find("a.buyring").click(function() {
				var $newRingtoneForm = $(this).parent().find("form");
		
				// * if already visible - close it 		
				if($newRingtoneForm.is('.cloned')) {
					Ringtones.close();
					return false;				
				}
				
				Ringtones.close();

				// select parent element (div#k_page or div#k_content) 
				var parentElement = 'k_page';

				// * get absolute position of A tag from selected parent element
				var l=t=0, o=this;
  			if (o.offsetParent)
					do {
						if(o.id==parentElement)break;
						l+=o.offsetLeft; 
						t+=o.offsetTop;
					} while(o=o.offsetParent);
				
				// * copy form to selected parent element
				var n = $newRingtoneForm.clone(true);
				n.appendTo('#'+parentElement); 		
				
				// * show with correct position
				if($(this).parent().is('.btn-big'))
					n.addClass('buyringformbig');
				else
					n.addClass('buyringform');
				n.css("left",l+"px");
				n.css("top",t+"px");				
				n.show();
			
				Ringtones.addKeyboard();
				Ringtones.$activeRingtoneForm = n;
				Ringtones.$activeRingtoneParent = $newRingtoneForm.addClass('cloned');

				return false;
			});
		})
		// add close button
		.append('<img class="close" src="' + textStrings.imagePath + 'icon-close.gif" title="' + textStrings.close + '" alt="' + textStrings.close + '" />')
		.find("img.close")
		.addClass("clickable")
		.click(function() {
			Ringtones.close();
		});
	
	},
	
	addKeyboard: function()
	{
		$(document).bind("keyup", function(event){
			if (event.keyCode == 27) {
				Ringtones.close();
				$(document).unbind('keyup');
			}
		});
	}
	
};



/*
 * Flash Reflections
 */
var Reflections = {

	init: function()
	{
		// find all elements with the class 'reflection' and replace them with flash
		$(".reflection").each(function() {
			// get image data
			var id = $(this).attr("id");
			var src = $(this).find("img").css("display", "block").attr("src");
			var width = Number($(this).find("img").attr("width"));
			var height = Number($(this).find("img").attr("height")) + 35;
			
			// create an id for the element, if it doesn't already have one
			if(!id) {
				id = "rand" + Math.round(Math.random() * 10000);
				$(this).attr("id", id);
			}
			
			// embed flash
//            src = "http://statcon.247base.com/xmlserver/img/420000-420999/3DF470FEE5560064E040010A0B0648BB.jpg";
//			width = 256;
//			height = 228;
//			src = "http://91.102.88.103/hostshops/247/type_d/sites/tdcdk2453325083407/jsp/public/img/bg_headtitle.gif";
    		var so = new SWFObject(frootdir + "swf/cover.swf", "cover" + id, width, height, "9", "#FFFFFF");			
			so.addParam("wmode", "transparent");
			so.addVariable("albumCover", src);
			so.write(id);
		});
	}
};	


var MusicPlayer =  {

	init: function()
	{
		$("#playstop")
			.addClass("clickable")
			.click(function(){
				PlayerControls.toggle();
				return false;
			}
		);
		
		$("#progress img").setPercent("horizontal", 0, 12, 124);
		
		$("#volume img").addClass("clickable").click(function(e) {
			var yPos = e.layerY;
			if(!yPos) yPos = e.offsetY;
			yPos = Math.max(17, yPos);
			yPos = Math.min(76, yPos);
			yPos -= 17;
			var percent = 100 - Math.round(100 / 59  * yPos);
			PlayerControls.setVolume(percent);
			return false;
		}).setPercent("vertical", 50, 17, 59);
	}
};



/*
 * Search Results
 */
var SearchResults = {
	
	init: function()
	{
		$(".mediatype h4")
		.addClass("clickable")
		.attr("title", textStrings.expand)
		.append("<span>" + textStrings.expand + "</span>")	
		.click(function() {
			SearchResults.toggle($(this));			
		})
		.not(".expanded")
		.next("div").hide();
	},
	
	toggle: function($element)
	{
		var expanded = $element.is(".expanded");		
		SearchResults.collapseAll();		
		if(!expanded) SearchResults.expand($element);
	},
	
	expand: function($element)
	{
		$element
		.addClass("expanded")
		.attr("title", textStrings.collapse)
		.next("div")
		.slideDown("fast");
		//.animate({height: "toggle"}, 250, "easeout");
	},
	
	collapse: function($element) 
	{		
		$element
		.removeClass("expanded")
		.attr("title", textStrings.expand)
		.next("div")
		.slideUp("fast");
		//.animate({height: "toggle"}, 250, "easeout");	
	},
	
	collapseAll: function()
	{
		$(".mediatype h4.expanded").each(function() {
			SearchResults.collapse($(this));
		});
	}

};



/*
 * Highslide
 */
var HighSlide = {

	activeId: null,
	
	disabled: function()
	{
		$("a.highslide").attr("title", "");
		$("a.highslide img").attr("title", "");
		$("a.highslide img").attr("alt", "");
		$("a.highslide").css("cursor", "default");
		$("a.highslide").click(function() {
            return false;
		});
	},

	init: function()
	{
	   // this.disabled();
	   // return;
        if($("a.highslide").size()) {
			// create the controlbar
			$(this.createControlbar()).insertAfter('#page');
			
			hs.graphicsDir = frootdir+'img/highslide/';
		
			hs.registerOverlay({
				thumbnailId: null,
				overlayId: 'controlbar',
				position: 'top right',
				hideOnMouseOut: true
			});
		}
		
		// create highslide caption using data pulled from the html
		$("a.highslide").click(function() {
			// close active image
			if(HighSlide.activeId) {
				hs.closeId(HighSlide.activeId);
			}
			
			// traverse the tr-element for data
			var $parent  = $(this).parent().parent().parent(); // $(this).parent("tr"); // this filtering does not work reliably??
			// create ID for this highslide element
			var id       = "highslideCaption" + Math.round(Math.random() * 10000);
			// get detail information to display within the highslide
            var artistlink   = $parent.find(".artist a:last").attr("href");
            var artistname   = $.trim($parent.find(".artist a:last").text());
			var album        = $.trim($parent.find(".album, .track, .title").text());
			var type         = $.trim($parent.find(".type").html());
			var price        = $.trim($parent.find(".price").html());
            var optionshtml  = $parent.find(".choose").clone();

			// save active id
			HighSlide.activeId = id;

			// create caption
			var caption = HighSlide.createCaption(id, artistname, album, type, price, optionshtml);
			$(this).parent().prepend(caption);
			return hs.expand(this, {captionId: id});
		});
	},
	
	createControlbar: function()
	{
		var html = '<div id="controlbar" class="highslide-overlay controlbar">';
//		html +=	'<a href="#" class="previous" onclick="return hs.previous(this)" title="' + textStrings.prev + '"></a>';
//		html +=	'<a href="#" class="next" onclick="return hs.next(this)" title="' + textStrings.next + '"></a>';
		html +=	'<a href="#" class="close" onclick="return hs.close(this)" title="' + textStrings.close + '"></a>';
		html +=	'</div>';
		return html;
	},
	
	createCaption: function(id, artist, album, type, price, optionshtml)
	{

		var caption = '<div class="highslide-caption" id="' + id + '">';
			caption += '<div style="float:left">';
				if(type) caption += '<span class="type">' + type + '</span>';
				if(artist) caption += '<span class="artist">' + artist + '</span>';
				if(album) caption += '<span class="album">' + album + '</span>';
				if(price) caption += '<span class="price">' + price + '</span>';
			caption += '</div>';
            caption += '<div style="float:right">';
                // Remove the grey "P" - icon, as the dynamic EventHandler for hover isn't 
                // applicable here and thus this isn't the same from usability point of view.
                if (optionshtml.find("a.tip") != null) {
                    optionshtml.find("a.tip").remove();
                }
                caption += optionshtml.html();
			caption += '</div>';
			caption += '<br class="clear" />';
		caption += '</div>';

		var captionobjects = $(caption);
		captionobjects.find("a.tip").tooltip();
		return captionobjects;
	}	

};



var Basket = {
	
	init: function()
	{
		$("#album-details .buy").click(function(e) {
			Basket.highlight($(this));
			return false;
		});
	},
	
	highlight: function($element)
	{
		// highlight basket
		$("#basket li").addClass("highlight");		
		
		// add to basket animation
		if(!$element.find("#addingtobasket").size()) {
			$element.append('<div id="addingtobasket"><p>' + textStrings.addingToBasket + '</p></div>');
		}
		
		// delay, fade out and remove
		setTimeout(function() {
			$("#addingtobasket").animate({opacity: 'hide'}, 1000, "easein", function() { 
				$(this).remove();
				$("body").unbind('mousemove');
			});
		}, 2500);
		
	}

};


/*
 * Articles
 */
var Articles = {

	active: 0,
	itv: null,
	delay: 3500,
	total: null,
	$prev: null,
	$next: null,

	init: function()
	{
		Articles.total = $("#articles li").size();
		
		if(!Articles.total) return false;
		
		// Hide all articles except the first
		$("#articles li:not(:first)").hide();
		
		// Pause interval when the user hovers over the articles block
		$("#articles")
		.hover(function() {
			Articles.stopInterval();
		},function() {
			Articles.startInterval();
		})
		.find("li").css("position", "absolute")
		.css("left", "10px");
		
		// Add links for changing the articles
		$('<div id="switcher"></div>').appendTo("#articles .content");		
		$("#articles li").each(function(index) {
			$('<a id="articles-switcher_' + index + '" href="#" title="' + textStrings.changeArticle + ' ' + (index+1) + '">' + index + '</a>')
			.appendTo("#switcher")
			.click(function() {
				var num = Number($(this).attr("id").split("_")[1]);
				Articles.show(num);
				return false;
			})
			.addClass(index ? "" : "active");
		});
	
		// Add previous button
		this.$prev = $('<div class="prev"><a class="clickable disabled">' + textStrings.prev + '</a></div>')
		.prependTo('#articles')
		.click(function() {
			if($(this).find("a").is(".disabled")) return false;
			Articles.show(Articles.active - 1);			
		});
		
		// Add next button
		this.$next = $('<div class="next"><a class="clickable">' + textStrings.next + '</a></div>')
		.prependTo('#articles')
		.click(function() {
			if($(this).find("a").is(".disabled")) return false;
			Articles.show(Articles.active + 1);
		});
		
		// Start interval
		Articles.startInterval();
	},
	
	startInterval: function() {		
		this.itv = setInterval(function() {
			var num = Articles.active + 1;
			if(num == Articles .total) num = 0;
			Articles.show(num);
		}, Articles.delay);
	},
	
	stopInterval: function() {
		clearInterval(this.itv);
	},
	
	show: function(num)
	{
		$("#articles li").eq(this.active).fadeOut("fast", function() {
			$(this).hide();
		});
		$("#articles li").eq(num).fadeIn("fast");
		
		$("#articles-switcher_" + this.active).removeClass("active");
		$("#articles-switcher_" + num).addClass("active");
		
		this.active = num;
		
		// enable/disable previous button
		(num > 0) ? this.$prev.find("a").removeClass("disabled") : this.$prev.find("a").addClass("disabled");
		
		// enable/disable next button
		(num == this.total - 1) ? this.$next.find("a").addClass("disabled") : this.$next.find("a").removeClass("disabled");	
	}
	
};


var Helpers = {

	getDimensions: function()
	{
		var dimensions = {};
		if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
		{
			dimensions.w = document.body.scrollWidth;
			dimensions.h = document.body.scrollHeight;
		}
		else // Explorer Mac;
		     //would also work in Explorer 6 Strict, Mozilla and Safari
		{
			dimensions.w = document.body.offsetWidth;
			dimensions.h = document.body.offsetHeight;
		}
		return dimensions;
	}
	
};




var TheOneAndOnlySearchForm = {
    default_value: "Skriv kunstner, album eller titel",

    init: function() {
        $("#search input.searchinput").focus(function() {
            if ($(this).val() == TheOneAndOnlySearchForm.default_value) {
                $(this).val("");
            }
        }).blur(function() {
            if ($(this).val() == "") {
                $(this).val(TheOneAndOnlySearchForm.default_value);
            }
        });
    }
};


var textStrings = {
	imagePath		:	frootdir+"img/",
	close			:	"Luk",
	expand			:	"Fold ud",
	collapse		:	"Fold sammen",
	prev			:	"Forrige",
	next			:	"N&aelig;ste",
	disableFlash	:	"Sl&aring; Flash fra",
	buy				:	"K&oslash;b",
	buyAlbum		:	"K&oslash;b album",
	download		:	"Download",
	addingToBasket	:	"L&aelig;gges i kurv",
	changeArticle	:	"Skift til artikel"
};



// On DOM ready
$(function() {	
		
	// Login
	Login.init();
	
	// Playlist
	Playlist.init();
	
	/* add link to all umap icons */
/*	$(".umap span:contains('umap')").click(function() {
		alert("link to umap");
	});
*/		
	
	// create sortable tables
	$("table.sortable").tablesorter().find("thead td").addClass("clickable");
	
	
	/* Tooltips */
	$("a.tip").tooltip();
	
	
	// Music Player
	MusicPlayer.init();
	
	
	// Video Player
	VideoPlayer.init();	
	
	
	// Hitlists
	Hitlists.init();
	
	
	// Newsletter
	Newsletter.init();
	
	
	// Ringtones
	Ringtones.init();
	
	
	// Replace all reflection images with flash
	Reflections.init();	
	
	
	// Search results
	SearchResults.init();
		
		
	// HighSlide
	HighSlide.init();
	
	
	// Articles
	Articles.init();
	
	
	Basket.init();
	
	
	/*
	$(".buy").click(function(e) {
		Basket.highlight(e);
		return false;
	});
	*/	
	
	
	TheOneAndOnlySearchForm.init();
});
function hideCollapsedElements() {
	$(".collapsed").hide().removeClass("collapsed");
}
hideCollapsedElements();


