/* IE6 flicker fix
-------------------------------------------------- */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}

/* Init */

$(document).ready(function() {
	$('.ihasahover').hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); });
});

/* Tabs switcher */

function showTab(ref,set){
	$('.'+set+' > LI > A').each(function(i,a){
		$(a).removeClass('active');
		$($(a).attr('href')).addClass('hidden');
	});
	$(ref).addClass('active');
	$($(ref).attr('href')).fadeIn(10).removeClass('hidden').css({display: ''});
	return false;
}
$(document).ready(function() {
	$('H2.expandable, H2.expandable01').each(function(i,a){
		$('A', a).click(function(){
			if($(this).hasClass('open')){
				$(this).removeClass('open');
				$($('A', a).attr('href')).addClass('hidden');
			} else {
				$(this).addClass('open');
				$($('A', a).attr('href')).removeClass('hidden');
			}
			return false;
		});
		if(!$('A', a).hasClass('open')){
			$($('A', a).attr('href')).addClass('hidden');
		}
	});
	handleDataTablesCurrencies.init();
});

/* Tooltip actions. */
function showTooltip(ref,txt,opt){
	$('body').append('<div id="tooltip"><div id="tooltip-ending"></div><div id="tooltip-inner">' + txt + '</div></div>');
	$('#tooltip').bgiframe();
	if(opt){ helper = opt; } else { helper = ref; }
	fit = $(document).width() - $(helper).offset().left - $('#tooltip').width();
	$('#tooltip')[0].style.top = $(helper).offset().top + $(helper).height() + 'px';
	if( fit < 0 ){
		$('#tooltip')[0].style.left = $(helper).offset().left + fit + 'px';	
		$('#tooltip-ending')[0].style.backgroundPosition = fit - fit - ($(document).width() - $(ref).offset().left) + 'px 0';
	} else {
		$('#tooltip')[0].style.left = $(helper).offset().left + 'px';
	}
	$(ref).bind('mouseout',function() {
		$('#tooltip').unbind('mouseout');
		$('#tooltip').remove();
		$('IFRAME.bgiframe').remove();
	});
}

(function($){
	/**
	 * @name bgiframe
	 * @type jQuery
	 * @cat Plugins/bgiframe
	 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
	 */
	$.fn.bgIframe = $.fn.bgiframe = function(s) {
		// This is only for IE6
		if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
			s = $.extend({
				top     : 'auto', // auto == .currentStyle.borderTopWidth
				left    : 'auto', // auto == .currentStyle.borderLeftWidth
				width   : 'auto', // auto == offsetWidth
				height  : 'auto', // auto == offsetHeight
				opacity : true,
				src     : 'javascript:false;'
			}, s || {});
			var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
				html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
						   'style="display:block;position:absolute;z-index:-1;'+
							   (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
							   'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
							   'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
							   'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
							   'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
						'"/>';
			return this.each(function() {
				if ( $('> iframe.bgiframe', this).length == 0 )
					this.insertBefore( document.createElement(html), this.firstChild );
			});
		}
		return this;
	};
})(jQuery);


var handleDataTablesCurrencies = {
	datatables_currency: 'dt_table_1',
	init: function(){
		handleDataTablesCurrencies.datatables_currency = 'dt_table_1'; // ($.cookie('datatables_currency') ? $.cookie('datatables_currency') : 'dt_table_1');

		$('.datatables_currency_selector A').click(function(){
			if ($(this).attr('rel') == 'dt_table_2') {
				handleDataTablesCurrencies.datatables_currency = 'dt_table_2';
				// $.cookie('datatables_currency', 'dt_table_2', {path: '/', expires: 1});
			} else {
				handleDataTablesCurrencies.datatables_currency = 'dt_table_1';
				// $.cookie('datatables_currency', 'dt_table_1', {path: '/', expires: 1});
			}
			handleDataTablesCurrencies.switchCurrency();
		});
		handleDataTablesCurrencies.switchCurrency();
	},
	switchCurrency: function(){
		if (handleDataTablesCurrencies.datatables_currency == 'dt_table_1') {
			$('.datatables_currency_selector A[rel="dt_table_2"]').removeClass('active');
			$('.datatables_currency_selector A[rel="dt_table_1"]').addClass('active');
			$('.dt_table_2').hide();
			$('.dt_table_1').show();
		} else {
			$('.datatables_currency_selector A[rel="dt_table_1"]').removeClass('active');
			$('.datatables_currency_selector A[rel="dt_table_2"]').addClass('active');
			$('.dt_table_2').show();
			$('.dt_table_1').hide();
		}
	}
};