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

jQuery.fn.hasClass = function(c) {
	return this.is('.'+c)
};

$(document).ready(function() {
	$('INPUT.onfocusclear').bind('focus',function () {
		if(!this.oldvalue){
			this.oldvalue = this.value;
		}
		if(this.value == this.oldvalue){
			this.value = '';
			$(this).removeClass('defaultvalue');
		}	
	}).bind('blur',function () {
		if(this.value == ''){
			this.value = this.oldvalue;
			$(this).addClass('defaultvalue');
		}
	});
	$('.ihasahover').hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); });
});

/* Tabs switcher */

function showTab(ref, scroll){
	scroll = typeof(scroll) != 'undefined' ? scroll : true;

	var pa = $('A.active',$($(ref).parents('UL')[0]));
	$(pa).removeClass('active');
	$(ref).addClass('active');
	if(scroll) {
		$($(pa).attr('href')).slideUp(300,function(){
			$($(ref).attr('href')).slideDown(300);
		});
	}
	else {
		$($(pa).attr('href')).hide();
		$($(ref).attr('href')).show();
	}
	return false;
}


function showPrevTab(set){
	var tmp1 = $('A',$(set));
	var tmp2;
	$(tmp1).each(function(i){
		if($(this).hasClass('active')){ tmp2 = i; }
	});
	$(tmp1[tmp2]).removeClass('active');
	if(tmp2==0){
		$(tmp1[tmp1.length-1]).addClass('active');
		$($(tmp1[tmp2]).attr('href')).slideUp(300,function(){
			$($(tmp1[tmp1.length-1]).attr('href')).slideDown(300);
		});
	} else {
		$(tmp1[tmp2-1]).addClass('active');
		$($(tmp1[tmp2]).attr('href')).slideUp(300,function(){
			$($(tmp1[tmp2-1]).attr('href')).slideDown(300);
		});
	}
	return false;
}
function showNextTab(set){
	var tmp1 = $('A',$(set));
	var tmp2;
	$(tmp1).each(function(i){
		if($(this).hasClass('active')){ tmp2 = i; }
	});
	$(tmp1[tmp2]).removeClass('active');
	if(tmp2==tmp1.length-1){
		$(tmp1[0]).addClass('active');
		$($(tmp1[tmp2]).attr('href')).slideUp(300,function(){
			$($(tmp1[0]).attr('href')).slideDown(300);
		});
	} else {
		$(tmp1[tmp2+1]).addClass('active');
		$($(tmp1[tmp2]).attr('href')).slideUp(300,function(){
			$($(tmp1[tmp2+1]).attr('href')).slideDown(300);
		});
	}
	return false;
}


/* 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);



/* Exapndable div */

$(document).ready(function() {
	$('H3.expandable,H3.expandable2').each(function(i,a){
		$(this).addClass('block').removeClass('hidden');
		$('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');
		}
	});
	if(top.location.hash && top.location.hash != '#' && $('a[href="'+top.location.hash+'"]').length > 0) {
		showTab($('a[href="'+top.location.hash+'"]', false).get(0));
	}
});