/* IE6 flicker fix
-------------------------------------------------- */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}
jQuery.fn.hasClass = function(c) { return this.is('.'+c) };

/* Init */

$(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,set){
    $('#'+set+' > LI > A').each(function(i,a){
        $(a).removeClass('active');
        $($(a).attr('href')).addClass('hidden');
    });
    $(ref).addClass('active');
    $($(ref).attr('href')).fadeIn(500).removeClass('hidden').css({display: ''});
    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)[0].offsetHeight + '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();
    });
}


$(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'); });
	/*$("#login").validate({
		rules: {
			login_username: {
				required: true,
				email: true
			},
			login_password: {
				required: true,				
				minlength: 6
			},			
		},
		messages: {
			login_username: {
				required: "Type your e-mail address."
			},
			login_password: {
				required: "This field is required.",
				minlength: jQuery.format("Password length: 6 char.")
			},
		},
		onkeyup: false
	})*/
});