var isIE6 = /MSIE 6/i.test(navigator.userAgent);
if(isIE6){ //if its ie6
	$(window).load(function(){ //window.load waits for all the images to load before firing
		$.getScript('/static/common/js/png-fix.js',function(){ //load png fix
			DD_belatedPNG.fix('.png-fix'); //fix all elements with class png-fix
		});
	});
}

$(function(){
	$('#account-name, #account-password').bind({
		'keypress'	: function(event){
			if(event.keyCode == 13){ //when enter is hit
				$('#login-form').submit();
				return false;
			}
		},
		'focus'		: function(event){
			//when password or username gains focus, hide the background that says username/password
			$(this).css('background-image','none');
			loginButton.keepOpen = true;
			loginButton.open();
		}
	});
	if($('#account-name').val() != ''){ $('#account-name').css('background-image','none'); }
	if($('account-password').val() != ''){ $('account-password').css('background-image','none'); }
	
	//hover effects for when someone hovers over the login bar
	$('#login').hover(loginButton.open,loginButton.close);
	if($('#link-with-cookie').length){
		$('a[href^=https://cp.light-speed.com]').each(function(){
			$(this).attr('href','javascript: void linkWithCookie(\''+$(this).attr('href')+'\')');
		});
	}
	if($('.live-chat-now').length){
		resizeWindow();
		$(window).resize(resizeWindow);	
	}
});

function linkWithCookie(url){
	$('#link-with-cookie').attr('action',url);
	try{
		_gaq.push(['_linkByPost',document.getElementById('link-with-cookie')]);
	}
	catch(e){
		//we don't want the page to crash just because the tracker wasn't loaded
	}
	$('#link-with-cookie').trigger('submit');
}

function openChat(){
	window.open('https://cp.light-speed.com/live_chat/live_chat.php?DOMAIN=instantventrilo.com','Live_Chat_Client','menubar=0,resizable=1,width=740,height=458');
}

var loginButton = {
	'keepOpen'	: false,
	'open'	: function(){
		$('#login').animate({'background-position':'0px 0px'},200);
	},
	'close'	: function(){
		if(!loginButton.keepOpen){
			$('#login').animate({'background-position':'-36px 0px'},200);	
		}
	}
}

function resizeWindow(){
	if($(window).width() >= ($('#header .inner-1').width()+80)){
		$('.live-chat-now').show();
	}
	else{
		$('.live-chat-now').hide()
	}
};

