$(function() {
	if ($.browser.msie) {
		$(document).pngFix();
	}
	if ($.browser.webkit) {
		$('#navigation > ul > li > ul').css('margin-top', '15px');
	}
	$('a.toggle.login').click(function (event) {
		event.preventDefault();
		$('#loginWrapper').slideToggle(600, function() {
			if ($('#loginWrapper:visible')) {
				$('#loginUrl').focus();
				$('#loginUrl').change();
			}
		});
	});
	$(window).bind('pageshow',function(){
		$('#navigation > ul > li > ul').hide();
	});
	$('#navigation > ul > li').hover(
		function () {
			$(this).find('ul').stop(true, true).animate({
				height: 'toggle',
				opacity: 'toggle'
			}, 400);
		}, 
		function () {
			$(this).find('ul').stop(true, true).animate({
				height: 'toggle',
				opacity: 'toggle'
			}, 100);
		}
	);
	$('a.show.login').click(function (event) {
		event.preventDefault();
		var optionIndex = 0;
		switch (true) {
			case ($(this).hasClass('advertiser')):
				$('#loginUser').attr('name', 'mail');
				$('#loginPass').attr('name', 'password');
				optionIndex = 1;
				break;
			case ($(this).hasClass('publisher')):
				optionIndex = 0;
				break;
			case ($(this).hasClass('referral')):
				optionIndex = 2;
				break;
		}
		$('#loginUrl').attr('selectedIndex', optionIndex).change();
		$('#loginWrapper').slideDown(600, function() {
			$('#loginUser').focus();
		});
	});
	/*$('#loginUrl').change(function() {
		$('#loginWrapper form').attr('action', $('#loginUrl').val());
	});*/
});

function changeLoginForm(val) {
	if(val == 'a') {
		document.getElementById('username_tr').style.display = 'none';
		document.getElementById('password_tr').style.display = 'none';
		document.getElementById('submit_tr').style.display = 'none';
		document.getElementById('advertiser_submit_tr').style.display = '';
	} else {
		document.getElementById('username_tr').style.display = '';
		document.getElementById('password_tr').style.display = '';
		document.getElementById('submit_tr').style.display = '';
		document.getElementById('advertiser_submit_tr').style.display = 'none';
	}
}

function advertiserClick() {	       
	newwin=window.open("http://adsystem.adbull.com/advertiser");
	if (window.focus) {newwin.focus()}
	return false;
}
