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

/* Copyright (c) 2006 Brandon Aaron (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.
 *
 * $LastChangedDate: 2007-07-21 18:44:59 -0500 (Sat, 21 Jul 2007) $
 * $Rev: 2446 $
 *
 * Version 2.1.1
 */

(function($){
$.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);

/* Loginbox functions */

$(document).ready(function() {
	$('#loginbox-opener').bind('mousedown',showBox);
});

var iamfirst = false;
function showBox() {
	if(iamfirst == true){
		iamfirst = false;
		return true;
	}
	ref = $('#loginbox-opener');
	if($('#loginbox:visible').length == 0){
		$('#loginbox')
			.show()
			.css({ left: $(ref).offset().left - $('#box01').offset().left })
			.bind('mousedown',setFirst)
		;
		$(document).bind('mousedown',showBox);
		$(ref).unbind('mousedown',showBox);
		$('DIV',ref).addClass('kana');
		return false;
	} else {
		$('#loginbox').hide().unbind('mousedown',setFirst);
		$(document).unbind('mousedown',showBox);
		$(ref).bind('mousedown',showBox);
		$('DIV',ref).removeClass('kana');
		return false;
	}
}
function setFirst(){ iamfirst = true; }


function toggleCal(ref,target){
	if ($('#'+target)[0].style.display != 'none'){
		$('#'+target)[0].style.display = 'none';
	} else {
		$('#'+target)[0].style.display = '';
		$('#'+target)[0].style.left = findPos(ref)[0] + ref.offsetWidth + 5 + 'px';
		$('#'+target)[0].style.top = findPos(ref)[1] + 'px';
	}
	return false;
}

function showDialog(ref,target){
	$('#'+target)[0].style.display = 'block';
	$('#'+target)[0].style.left = findPos($('#'+ref)[0])[0] + 'px';
	$('#'+target)[0].style.top = findPos($('#'+ref)[0])[1] + $('#'+ref)[0].offsetHeight + 1 + 'px';
}

