var rootScript = $('script[data-url-root]'),
	URL_ROOT = rootScript.data('url-root');
	FULL_URL_ROOT = rootScript.data('full-url-root');
$.CMS = {
	FULL_URL_ROOT : FULL_URL_ROOT,
	URL_ROOT : URL_ROOT,
	URL_DATA : URL_ROOT+'cms-data/'
};

// Browsers that support HTML5 history.pushState() are modern enough
var modern = history && history.pushState;

function setState(url, title) {
	var state = {url : url};
	if(modern) {
		history.pushState(state, title, url);
	} else {
		$.bbq.pushState(state, 2);
	}
	loadPage(state);
	
	// Google analytics tracking
	if(window._gaq) {
		window._gaq.push(['_trackPageview', url]);
	}
	// Snoobi
	if(window.snoobi) {
		snoobi.trackPageView(url);
	}
	
	return false;
}

// tipsy, facebook style tooltips for jquery
// version 1.0.0a
// (c) 2008-2010 jason frame [jason@onehackoranother.com]
// released under the MIT license
(function(a){function b(b,c){this.$element=a(b),this.options=c,this.enabled=!0,this.fixTitle()}b.prototype={show:function(){var b=this.getTitle();if(b&&this.enabled){var c=this.tip();c.find(".tipsy-inner")[this.options.html?"html":"text"](b),c[0].className="tipsy "+this.options.style,c.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).appendTo(document.body),b=a.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight});var d=c[0].offsetWidth,e=c[0].offsetHeight,f=typeof this.options.gravity=="function"?this.options.gravity.call(this.$element[0]):this.options.gravity,g;switch(f.charAt(0)){case"n":g={top:b.top+b.height+this.options.offset,left:b.left+b.width/2-d/2};break;case"s":g={top:b.top-e-this.options.offset,left:b.left+b.width/2-d/2};break;case"e":g={top:b.top+b.height/2-e/2,left:b.left-d-this.options.offset};break;case"w":g={top:b.top+b.height/2-e/2,left:b.left+b.width+this.options.offset}}f.length==2&&(g.left=f.charAt(1)=="w"?b.left+b.width/2-15:b.left+b.width/2-d+15),c.css(g).addClass("tipsy-"+f),this.options.fade?c.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity},200):c.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(200,function(){a(this).remove()}):this.tip().remove()},fixTitle:function(){var a=this.$element;(a.attr("title")||typeof a.attr("original-title")!="string")&&a.attr("original-title",a.attr("title")||"").removeAttr("title")},getTitle:function(){var a,b=this.$element,c=this.options;this.fixTitle(),c=this.options,typeof c.title=="string"?a=b.attr(c.title=="title"?"original-title":c.title):typeof c.title=="function"&&(a=c.title.call(b[0]));return(a=(""+a).replace(/(^\s*|\s*$)/,""))||c.fallback},tip:function(){this.$tip||(this.$tip=a('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'));return this.$tip},validate:function(){this.$element[0].parentNode||(this.hide(),this.options=this.$element=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled}},a.fn.tipsy=function(c){function f(d){var e=a.data(d,"tipsy");e||(e=new b(d,a.fn.tipsy.elementOptions(d,c)),a.data(d,"tipsy",e));return e}function e(){var a=f(this);a.hoverState="in",c.delayIn==0?a.show():(a.fixTitle(),setTimeout(function(){a.hoverState=="in"&&a.show()},c.delayIn))}function d(){var a=f(this);a.hoverState="out",c.delayOut==0?a.hide():setTimeout(function(){a.hoverState=="out"&&a.hide()},c.delayOut)}if(c===!0)return this.data("tipsy");if(typeof c=="string"){var g=this.data("tipsy");g&&g[c]();return this}c=a.extend({},a.fn.tipsy.defaults,c),c.live||this.each(function(){f(this)});if(c.trigger!="manual"){g=c.live?"live":"bind";var h=c.trigger=="hover"?"mouseleave":"blur";this[g](c.trigger=="hover"?"mouseenter":"focus",e)[g](h,d)}return this},a.fn.tipsy.defaults={delayIn:0,delayOut:0,fade:!1,fallback:"",gravity:"n",html:!1,live:!1,offset:0,opacity:.8,title:"title",trigger:"hover",style:""},a.fn.tipsy.elementOptions=function(b,c){return a.metadata?a.extend({},c,a(b).metadata()):c},a.fn.tipsy.autoNS=function(){return a(this).offset().top>a(document).scrollTop()+a(window).height()/2?"s":"n"},a.fn.tipsy.autoWE=function(){return a(this).offset().left>a(document).scrollLeft()+a(window).width()/2?"e":"w"}})(jQuery);

/*
 * jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
 * http://benalman.com/projects/jquery-bbq-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M<N?O[P]||(R[M+1]&&isNaN(R[M+1])?{}:[]):J}}else{if($.isArray(H[P])){H[P].push(J)}else{if(H[P]!==i){H[P]=[H[P],J]}else{H[P]=J}}}}else{if(P){H[P]=F?i:""}}});return H};function z(H,F,G){if(F===i||typeof F==="boolean"){G=F;F=a[H?D:A]()}else{F=E(F)?F.replace(H?w:x,""):F}return l(F,G)}l[A]=B(z,0);l[D]=v=B(z,1);$[y]||($[y]=function(F){return $.extend(C,F)})({a:k,base:k,iframe:t,img:t,input:t,form:"action",link:k,script:t});j=$[y];function s(I,G,H,F){if(!E(H)&&typeof H!=="object"){F=H;H=G;G=i}return this.each(function(){var L=$(this),J=G||j()[(this.nodeName||"").toLowerCase()]||"",K=J&&L.attr(J)||"";L.attr(J,a[I](K,H,F))})}$.fn[A]=B(s,A);$.fn[D]=B(s,D);b.pushState=q=function(I,F){if(E(I)&&/^#/.test(I)&&F===i){F=2}var H=I!==i,G=c(p[g][k],H?I:{},H?F:2);p[g][k]=G+(/#/.test(G)?"":"#")};b.getState=u=function(F,G){return F===i||typeof F==="boolean"?v(F):v(G)[F]};b.removeState=function(F){var G={};if(F!==i){G=u();$.each($.isArray(F)?F:arguments,function(I,H){delete G[H]})}q(G,2)};e[d]=$.extend(e[d],{add:function(F){var H;function G(J){var I=J[D]=c();J.getState=function(K,L){return K===i||typeof K==="boolean"?l(I,K):l(I,L)[K]};H.apply(this,arguments)}if($.isFunction(F)){H=F;return G}else{H=F.handler;F.handler=G}}})})(jQuery,this);
/*
 * jQuery hashchange event - v1.2 - 2/11/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);

/* Image preloader */
(function(c){var d=[];c.preloadImages=function(){for(var a=arguments.length;a--;){var b=document.createElement("img");b.src=arguments[a];d.push(b)}}})(jQuery);


$.fn.textGradient = function(from, to, h, a, b) {
	return this.each(function() {
		var that = $(this);
		if(that.is('.rainbow')) {
			return;
		}
		function v(a,b) {
			return parseInt(a.substr(b, 2), 16);
		}
		from = from.replace('#', '');
		to = to.replace('#', '');
		var i,
			spans,
			wordSpans = [],
			words = that.text().split(' '),
			n = words.length,
			word,
			f = [v(from,0), v(from,2), v(from,4)],
			t = [v(to,0), v(to,2), v(to,4)],
			hh = h - a - b;
		for(i = 0; i < n; i++) {
			word = words[i]+'&nbsp;';
			spans = ['<span class="base" style="color:rgb(' + f.join(',') + ');">' + word + '</span>'];
			for(j = 0; j < h; j++) {
				var ratio = Math.max(0, Math.min(1, (j - a) / hh)), ratio2 = 1 - ratio,
					c = [Math.round(f[0] * ratio2 + t[0] * ratio),
						Math.round(f[1] * ratio2 + t[1] * ratio),
						Math.round(f[2] * ratio2 + t[2] * ratio)];
				spans.push('<span style="color:rgb(' + c.join(',') + ');"><span style="top:' + (-j) + 'px;" alt="">' + word + '</span></span>');
			}
			wordSpans.push('<span style="height:'+h+'px">'+spans.join('')+'</span>');
		}
		that.addClass('rainbow').html(wordSpans.join(''));
	});
};

function enablePrices(context) {
	if(new Date('2011-07-01') > new Date()) {
		$('table.styled td', context).each(function() {
			var that = $(this), text = $.trim(that.text()), eur = text.match(/^([0-9]+,[0-9]+) €$/);
			if(eur) {
				$('<span>'+text+'</span>').appendTo(that.empty().css('cursor', 'default')).tipsy({
					gravity : 'sw',
					offset : 0,
					opacity : 1,
					fade : true,
					style : 'other',
					fallback : (parseFloat(eur[1].replace(',', '.')) * 15.6466).toFixed(2).replace('.', ',')+' EEK'
				});
			}
		});
	}
}

var loadedUrl,
	cache = {},
	content = $('.content'),
	speed = 500,
	bgImages = {},
	buttonsTimeout;

function ajaxCache(url) {
	if(modern && !cache[url]) {
		$.get(url, function(data) {
			cache[url] = data;
		}, 'html');
	}
}

function loadPage(state) {
	if(state === null) {
		//return;
	}
	var gotData = false,
		timeout = false,
		url = state && state.url ? state.url : location.href.replace($.CMS.FULL_URL_ROOT, ''),
		goingLeft;
	
	if($('.shelf').length) {
		goingLeft = $('.shelf').find('a[href="'+url+'"]').closest('td').prevAll('td').length < $('.shelf').find('a[href="'+loadedUrl+'"]').closest('td').prevAll('td').length;
	} else if($('.history-menu').length) {
		goingLeft = $('.history-menu').find('a[href="'+url+'"]').closest('li').prevAll('li').length < $('.history-menu').find('a[href="'+loadedUrl+'"]').closest('li').prevAll('li').length;
	} else if($('.here').length) {
		goingLeft = !url.match(/([0-9]+):([0-9]+)$/) || (url.match(/([0-9]+):([0-9]+)$/)[2] << 0) < ($('.here').attr('href').match(/([0-9]+):([0-9]+)$/)[2] << 0);
	}
		
	if(url == loadedUrl || !loadedUrl) {
		loadedUrl = url;
		return;
	} 
	loadedUrl = url;
	
	function loaded(data) {
		// Switch content
		var newContent = data.find('.content'), bgLoaded = false, bgWaiting = false;
		content.replaceWith(newContent);
		content = newContent;
		
		var style = data.find('#new-styles').data('styles');
		$('body').find('#new-global-styles').remove().end().append('<style id="new-global-styles">'
			+'#menu>ul>li>a:not(.open), #lngmenu>ul>li>a { color: '+style.menu_color+'; }'
			+'#menu ul li a:hover, #lngmenu ul li a:hover { color: '+style.menu_hover_color+'; }'
			+'#menu ul ul li a { color: '+style.menu_open_text_color+'; }'
			+'.tipsy-inner { background-color: '+style.menu_open_color+'; }'
			+'.tipsy-arrow { border-color: '+style.menu_open_color+'; }'
			+'body, a.ads-video { color: '+style.text_color+'; }'
			+'.oldads .title, .content-ad h2, a.ads-video:hover { color: '+style.subtitle_color+'; }'
			+(style.title_shadow ? 'h1 { text-shadow: -2px 2px 2px rgba(0,0,0,.3); }' : 'h1 { text-shadow: none; }' )
			+(style.text_shadow ? '#main .narrow p, #main .nawwor ul, #main .narrow ol { text-shadow: 1px -1px rgba(0,0,0,.22); }' : '#main .narrow p, #main .nawwor ul, #main .narrow ol { text-shadow: none; }' )
			+(style.hide_title ? 'h1.title { visibility : hidden; }' : 'h1.title { visibility : visible; }')
			+'.prev, .next { background-image: url('+style.arrows+'); }'
		+'</style>');
		
		if(buttonsTimeout) {
			clearTimeout(buttonsTimeout);
			buttonsTimeout = false;
		}
		
		function bgDone() {
			if(bgWaiting) {
				bgNow();
			} else {
				bgLoaded = true;
			}
		}
		function bgNow() {
			bgLoaded = true;
			$('#bodybg').css('background-image', 'url('+style.background_image+')').fadeTo(0, 0).fadeTo(speed * 2, 1, function() {
				$('body').css('background-image', 'url('+style.background_image+')');
				$(this).css('background-image', 'none');
			});
			$('#footerbg').css('background-image', 'url('+style.footer_image+')').fadeTo(0, 0).fadeTo(speed * 2, 1, function() {
				$('#footer').css('background-image', 'url('+style.footer_image+')');
				$(this).css('background-image', 'none');
			});
			buttonsTimeout = setTimeout(function() {
				buttonsTimeout = false;
				$('.prev,.next,.here', '#main').remove();
				if(!$.browser.msie || $.browser.version > 8) {
					data.find('.prev,.next').appendTo('#main').fadeTo(0, 0).fadeTo(speed, 1);
				} else {
					data.find('.prev,.next').appendTo('#main');
				}
				data.find('.here').appendTo('#main');
			}, speed);
			
			if($('.autoplay-video').length) {
				$('.oldads-inner a:first').click();
			}
		}
		bgImages[style.background_image] = $('<img>').attr('src', style.background_image);
		setTimeout(function() {
			if(bgImages[style.background_image][0].complete) {
				bgDone();
			} else {
				bgImages[style.background_image].bind('load', bgDone);
			}
		}, 1);
		
		// Switch other elements
		data.find('.shelf').appendTo('#main').fadeTo(0, 0).fadeTo(speed, 1);
		
		// Switch history menu
		$('.history-menu').remove();
		data.find('.history-menu').prependTo('#main');
		
		// Enable title gradients
		if(!style.hide_title && style.title_top) {
			$('h1').textGradient(style.title_top, style.title_bottom, 65, 15, 12);
		}
		
		// Enable price converter
		enablePrices(content);
		
		// Move content back to view
		content.css('left', goingLeft ? '-150%' : '150%').animate({
			left : '0%'
		}, speed, function() {
			if(bgLoaded) {
				bgNow();
			} else {
				bgWaiting = true;
			}
		});
	}
	function tryLoaded(data) {
		if(data) {
			// Update window title
			document.title = data.match(/<title>([^<]*)<\/title>/i)[1];
			data = $(data.replace(/^[\s\S]*<body[^>]*>|<\/body>[\s\S]*$|<script[^<]*<\/script>|<style>[\s\S]*<\/style>|<!--[\s\S]*-->|\n\s*(:?\n)/ig, '').replace(/\n\s*/g, "\n")).wrapAll('<div>').parent();
			
			var style = data.find('#new-styles').data('styles');
			$('body').animate({ backgroundColor : style.background_color }, speed * 2);
			$('#menu>ul>li>a:not(.open), #lngmenu>ul>li>a').animate({ color : style.menu_color }, speed * 2, function() {
				$(this).removeAttr('style');
			});
			$('#menu>ul>li>a.open').animate({ color : style.menu_hover_color }, speed * 2); 
			$('#menu li ul').animate({ backgroundColor : style.menu_open_color }, speed * 2);
			
			$.preloadImages.apply(null, style.preload);
			$.each(style.preloadajax, function(_, url) {
				ajaxCache(url);
			});
			
			if(timeout) {
				loaded(data);
			} else {
				gotData = data;
				
				bgImages[style.background_image] = $('<img>').attr('src', style.background_image);
				bgImages[style.footer_image] = $('<img>').attr('src', style.footer_image);
				bgImages[style.arrows] = $('<img>').attr('src', style.arrows);
			}
		} else {
			if(gotData) {
				loaded(gotData);
			} else {
				timeout = true;
			}
		}
	}

	content.stop().animate({
		left : goingLeft ? '150%' : '-150%'
	}, speed, function() {
		tryLoaded();
	});
	$('.tipsy').fadeOut(function() {
		$(this).remove();
	});
	setTimeout(function() {
		$('.tipsy').fadeOut(function() {
			$(this).remove();
		});
	}, 500);
	
	$('.shelf', '#main').fadeOut(500, function() {
		$(this).remove();
	});
	if(!$.browser.msie || $.browser.version > 8) {
		$('.prev,.next', '#main').fadeOut(500, function() {
			$(this).remove();
		});
	} else {
		$('.prev,.next', '#main').remove();
	}
	$('.here', '#main').remove();

	if(cache[url]) {
		tryLoaded(cache[url]);
	} else {
		$.get(url, function(data) {
			cache[url] = data;
			tryLoaded(data);
		}, 'html');
	}
}

if(modern) {
	$(window).bind('popstate', function(e) {
		loadPage(e.originalEvent.state);
	});
	loadPage(null);

	$('body').delegate('.prev, .next, .shelf a, .history-menu a', 'click', function(e) {
		e.preventDefault();
		var link = $(this);
		link.addClass('open').closest('li').siblings().children().removeClass('open');
		link.closest('ul').parent().children('a').addClass('open').closest('li').siblings().children().removeClass('open');
		link.closest('ul').closest('li').children('a').addClass('open').end().siblings().children('a').find('.open').removeClass('open');
		return setState(link.attr('href'), link.text() || link.attr('title'));
	});
}

if(!$.browser.msie || $.browser.version > 8) {
	$('body').delegate('.shelf a', 'mouseenter', function() {
		$(this).closest('td').siblings().stop().fadeTo(300, 0.5);
		$(this).stop().fadeTo(50, 1);
	}).delegate('.shelf a', 'mouseleave', function() {
		$(this).closest('td').siblings().stop().fadeTo(300, 1);
	});
} else {
	$('body').delegate('.shelf a', 'mouseenter', function() {
		$(this).css({
			marginBottom : 2
		});
	}).delegate('.shelf a', 'mouseleave', function() {
		$(this).css({
			marginBottom : 0
		});
	});
}
$('body').delegate('#fp-small-banners .banner', 'mouseenter', function() {
	$(this).siblings().stop().fadeTo(300, 0.8);
	$(this).stop().fadeTo(50, 1);
}).delegate('#fp-small-banners .banner', 'mouseleave', function() {
	$(this).siblings().stop().fadeTo(300, 1);
});

$('body').delegate('a.overlay', 'click', function(e) {
	e.preventDefault();
	var img = $('<img src="'+$(this).attr('href')+'">').load(function() {
		if(!$.browser.msie || $.browser.version > 8) {
			$('#overlay,#overlay-picture').fadeIn();
		} else {
			$('#overlay,#overlay-picture').show();
		}
		if(img.height() > $(window).height() - 100) {
			img.height($(window).height() - 100);
		}
		$('#overlay-picture').css({
			marginLeft : -img.width() / 2 - 5,
			marginTop : -img.height() / 2
		});
	});
	img.each(function() {
		if(this.complete) $(this).trigger('load');
	}).appendTo('#overlay-picture');
}).delegate('#overlay,#overlay-close', 'click', function() {
	if(!$.browser.msie || $.browser.version > 8) {
		$('#overlay,#overlay-picture').fadeOut(function() {
			$('#overlay-picture').find('img,iframe').remove();
		});
	} else {
		$('#overlay,#overlay-picture').hide();
		$('#overlay-picture').find('img,iframe').remove();
	}
});

$('body').delegate('a', 'click', function(e) {
	var url = $(this).attr('href'), m = url.match('http:\/\/(?:www.)?youtube.com/watch?.*v=([^&]*)');
	if(m) {
		//<iframe width="425" height="349" src="http://www.youtube.com/embed/-iCEN8BC6a4?rel=0" frameborder="0" allowfullscreen></iframe>
		e.preventDefault();
		var width = 640, height = 385;
		var frame = $('<iframe width="'+width+'" height="'+height+'" src="http://www.youtube.com/embed/'+m[1]+'?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
		$('#overlay-picture').css({
			marginLeft : -width / 2 - 5,
			marginTop : -height / 2
		});
		frame.appendTo('#overlay-picture');
		if(!$.browser.msie || $.browser.version > 8) {
			$('#overlay,#overlay-picture').fadeIn();
		} else {
			$('#overlay,#overlay-picture').show();
		}
	}
});

jQuery(function($){
	$('.prev, .next, .shelf a').tipsy({
		live : true,
		gravity : 's',
		offset : 10,
		opacity : .9,
		fade : true
	});
	$('table.styled a[href="#"]').tipsy({
		live : true,
		gravity : 'sw',
		offset : 0,
		opacity : 1,
		fade : true,
		style : 'other'
	});
	$('body').delegate('table.styled a[href="#"]', 'click', function() {
		return false;
	}).delegate('.oldads-next', 'click', function() {
		var that = $(this),
			ads = that.closest('.oldads'),
			outer = ads.find('.oldads-outer'),
			inner = ads.find('.oldads-inner'),
			end = inner.find('.oldads-end'),
			pos = inner.data('pos') || 0,
			maxPos = end.position().left - parseInt(inner.css('marginLeft'), 10)  - 290,
			newPos;
			
		if(-pos < maxPos) {
			newPos = pos - 4 * 82;
			inner.animate({
				marginLeft : newPos
			}, {
				queue : false,
				duration : 500
			}).data('pos', newPos);
			ads.find('.oldads-prev').show();
			outer.addClass('scrolled');
		}
		if(-newPos >= maxPos) {
			that.hide();
		}
		return false;
	}).delegate('.oldads-prev', 'click', function() {
		var that = $(this),
			ads = that.closest('.oldads'),
			outer = ads.find('.oldads-outer'),
			inner = ads.find('.oldads-inner'),
			end = inner.find('.oldads-end'),
			pos = inner.data('pos') || 0,
			minPos = 0,
			newPos;
			
		if(-pos > minPos) {
			newPos = pos + 4 * 82;
			inner.animate({
				marginLeft : newPos
			}, {
				queue : false,
				duration : 500
			}).data('pos', newPos);
			ads.find('.oldads-next').show();
		}
		if(-newPos <= minPos) {
			that.hide();
			outer.removeClass('scrolled');
		}
		return false;
	});
	
	enablePrices('body');
	
	setTimeout(function() {
		$('.fp-news').each(function() {
			var links = $('a:not(.archive)', this), maxBottom = $(this).height();
			while(links.last().position().top + links.last().height() > maxBottom) {
				links.last().remove();
				links = links.not(':last');
			}
		});
	}, 50);
	
	$('#menu a').each(function() {
		var that  = $(this);
		if(that.attr('href').match(/^http:/)) {
			that.attr('target', '_blank');
		}
	});
	
	if($.browser.msie) {
		$('.oldads').each(function() {
			var that = $(this);
			that.find('.title').pir({
				font : 1,
				color : (''+that.data('color')).replace(/^#/g, ''),
				bg : (''+that.data('bg')).replace(/^#/g, ''),
				wrap : true
			});
			that.find('span').pir({
				font : 2,
				hoverColor : (''+that.data('color')).replace(/^#/g, ''),
				color : (''+that.data('hover')).replace(/^#/g, ''),
				bg : (''+that.data('bg')).replace(/^#/g, ''),
				wrap : true
			});
		});
	}
});

