sub_timeout=[];
area_timeout=[];

function menu_out(menu_id, slideout) {
	if (!slideout)
		slideout=false;

	$('div#'+menu_id+'_sub').slideUp(100, function() {
		if ($('img#'+menu_id).attr('src').indexOf('_over')>0 && !$('img#'+menu_id).hasClass('menu_active'))
  		$('img#'+menu_id).attr('src', $('img#'+menu_id).attr('src').replace('_over.gif', '.gif'));

		if (slideout) {
			mainmenu_check =  $('img#'+menu_id).parents('div.mainmenu_item');
			if (mainmenu_check.length>0) {
				if (mainmenu_check.hasClass('cat')) doarea='cat';
				if (mainmenu_check.hasClass('dog')) doarea='dog';
				if (mainmenu_check.hasClass('rodent')) doarea='rodent';
				area_timeout[doarea] = window.setTimeout(function() { slide_out(doarea) }, 10);
			}
		}
	});
}

function slide_out(doarea) {
	xleft = (doarea == 'cat') ? 621 : 508;
	$('div.mainmenu div.mainmenu_item.'+doarea).find('div.rightside').animate({left: [-xleft, 'swing']}, { queue:false, duration: 500});

	$('div.mainmenu div.mainmenu_item.'+doarea).find('img[id]').each( function() {
		menu_out($(this).attr('id'));
//		$('div#'+$(this).attr('id')+'_sub').slideUp(100);
	});
}

function lang_choose() {
	$.prompt('<img src="images/main/language_fail.gif">',{ show: 'dropIn' });
}

$.fn.extend({
  dropIn: function(speed, callback){
    var $t = $(this);

    if($t.css("display") == "none") {
      eltop = $t.css('top');
      elouterHeight = $t.outerHeight(true);

      $t.css({ top: -elouterHeight, display: 'block' }).animate({ top: eltop },speed,'swing', callback);
    }
  }
});

function trader_login() {
	$.prompt('<iframe src="trader_login_mask.php" frameborder=0 scrolling="no" style="overflow: hidden; width: 580px; height: 505px; border: none; margin: 0px; padding: 0px; margin-left: 15px; margin-right: 15px;"></iframe>', { classes: 'download', buttons: false, show: 'dropIn' });
}

function shop_checkout() {
	$.prompt('<iframe src="shop_checkout.php" frameborder=0 scrolling="no" style="overflow: hidden; width: 580px; height: 505px; border: none; margin: 0px; padding: 0px; margin-left: 15px; margin-right: 15px;"></iframe>', { classes: 'checkout', buttons: false, show: 'dropIn' });
}

function lottery(game) {
	$.prompt('<iframe src="lottery.php?game='+game+'" frameborder=0 scrolling="no" ALLOWTRANSPARENCY="true" style="overflow: hidden; width: 608px; height: 535px; border: none; margin: 0px; padding: 0px; background: url(\'images/lottery/back_'+game+'.png\') no-repeat;"></iframe>', { classes: 'lottery', prefix: 'jqil', buttons: false, show: 'dropIn' });
}

function infopage(infopage) {
	$.prompt('<iframe src="infopage.php?infopage='+infopage+'" frameborder=0 scrolling="no" ALLOWTRANSPARENCY="true" style="overflow: hidden; width: 638px; height: 535px; border: none; margin: 0px; padding: 0px; background: url(\'images/infopage/back_'+infopage+'.png\') no-repeat;"></iframe>', { classes: 'infopage', prefix: 'jqii', buttons: false, show: 'dropIn' });
}

function bigsmell() {
	$.prompt('<iframe src="bigsmell.php" frameborder=0 scrolling="no" ALLOWTRANSPARENCY="true" style="overflow: hidden; width: 608px; height: 532px; border: none; margin: 0px; padding: 0px; background: url(\'images/bigsmell/back_bigsmell.png\') no-repeat;"></iframe>', { classes: 'bigsmell', prefix: 'jqii', buttons: false, show: 'dropIn' });
}

function hellokitty() {
	$.prompt('<iframe src="hellokitty.php" frameborder=0 scrolling="no" ALLOWTRANSPARENCY="true" style="overflow: hidden; width: 642px; height: 575px; border: none; margin: 0px; padding: 0px; background: url(\'images/hellokitty/back_hellokitty.png\') no-repeat;"></iframe>', { classes: 'hellokitty', prefix: 'jqii', buttons: false, show: 'dropIn' });
}

$(document).ready(function(){
	$('h1').each( function() {
		if($(this).attr('class')>'') {
			$(this).html($('<img>').attr('src', jsimagepath+'language/'+jslanguage+'/headlines/'+$(this).attr('class')+'.gif').attr('alt', $(this).text()).attr('title', $(this).text()));
		}
	});

	search_start = $('div.content.navigation_top input#search').val();

	$('div.content.navigation_top input#search').focus(function() {
		if ($(this).val()==search_start)
			$(this).val('');
	});

	$('div.content.navigation_top input#search').blur(function() {
		if ($(this).val()=='')
			$(this).val(search_start);
	});

	$('div.content.navigation_top input#submit').mouseover( function() {
		$(this).attr('src', jsimagepath+'language/'+jslanguage+'/button_search_over.png');
	});

	$('div.content.navigation_top input#submit').mouseout( function() {
		$(this).attr('src', jsimagepath+'language/'+jslanguage+'/button_search.png');
	});

	$('div.mainmenu div.mainmenu_item').mouseover( function() {
		if ($(this).hasClass('cat')) { doarea='cat'; slide_out('dog'); slide_out('rodent'); }
		if ($(this).hasClass('dog')) { doarea='dog'; slide_out('cat'); slide_out('rodent'); }
		if ($(this).hasClass('rodent')) { doarea='rodent'; slide_out('cat'); slide_out('dog'); }

		$('div.navigation_top > div.menu_items').find('img[id]').each( function() {
			menu_out($(this).attr('id'));
		})

  	if (area_timeout[doarea])
  		window.clearTimeout(area_timeout[doarea]);

		$(this).find('div.rightside').animate({left: [0, 'swing']}, { queue:false, duration: 500});
	});

	$('div.mainmenu div.mainmenu_item').mouseout( function() {
		if ($(this).hasClass('cat')) doarea='cat';
		if ($(this).hasClass('dog')) doarea='dog';
		if ($(this).hasClass('rodent')) doarea='rodent';
		area_timeout[doarea] = window.setTimeout(function() { slide_out(doarea) }, 1);
	});

	$('div.menu_items img').mouseover( function() {
			if ($(this).attr('src').indexOf('_over')==-1)
				$(this).attr('src', $(this).attr('src').replace('.gif', '_over.gif'));
	});

	$('div.menu_items img').mouseout( function() {
		if ($(this).attr('id') && ($(this).parents('div.rightside:animated').css('left')=='0px' || $(this).parents('div.rightside:animated').css('left')==null)) {
			sub_timeout[$(this).attr('id')] = window.setTimeout(function() { menu_out($(_self).attr('id')); }, 10);
		}
		else {
			if ($(this).attr('src').indexOf('_over')>0 && !$(this).hasClass('menu_active'))
				$(this).attr('src', $(this).attr('src').replace('_over.gif', '.gif'));
		}
	});

	$('div.menu_items img[id]').mousemove( function() {
  	if (sub_timeout[$(this).attr('id')])
  		window.clearTimeout(sub_timeout[$(this).attr('id')]);

		dodropdown=true;

		if ($(this).parents('div.rightside').length>0) {
			dodropdown=false;
			if ($(this).parents('div.rightside:animated').css('left')=='0px' || $(this).parents('div.rightside:animated').css('left')==null)
				dodropdown=true;
		}

		if (dodropdown && $('div#'+$(this).attr('id')+'_sub:hidden').length>0) {
			posi = $(this).offset();
			if ($(this).parents('div.navigation_top').length>0)
	  		$('div#'+$(this).attr('id')+'_sub').css('left', posi.left).css('top', posi.top+35).slideDown(100);
	  	else
	  		$('div#'+$(this).attr('id')+'_sub').css('left', posi.left).css('top', posi.top+33).slideDown(100);
	  }
	});

	$('div.menu_items img[id]').mouseout( function() {
  	_self = this;
  	if (sub_timeout[$(this).attr('id')])
  		window.clearTimeout(sub_timeout[$(this).attr('id')]);

	 	sub_timeout[$(this).attr('id')] = window.setTimeout(function() { menu_out($(_self).attr('id')); }, 10);
	});

	$('div.menu_subs > div[id]').mouseover( function() {
  	if (sub_timeout[$(this).attr('id').replace('_sub', '')])
  		window.clearTimeout(sub_timeout[$(this).attr('id').replace('_sub', '')]);

		mainmenu_check =  $('img#'+$(this).attr('id').replace('_sub', '')).parents('div.mainmenu_item');
		if (mainmenu_check.length>0) {
			if (mainmenu_check.hasClass('cat')) doarea='cat';
			if (mainmenu_check.hasClass('dog')) doarea='dog';
			if (mainmenu_check.hasClass('rodent')) doarea='rodent';
			window.clearTimeout(area_timeout[doarea]);
		}

  	if ($('img#'+$(this).attr('id').replace('_sub', '')).attr('src').indexOf('_over')==-1)
  		$('img#'+$(this).attr('id').replace('_sub', '')).attr('src', $('img#'+$(this).attr('id').replace('_sub', '')).attr('src').replace('.gif', '_over.gif'));
	});

	$('div.menu_subs > div[id]').mouseout( function() {
  	_self = this;
  	if (sub_timeout[$(this).attr('id').replace('_sub', '')])
  		window.clearTimeout(sub_timeout[$(this).attr('id').replace('_sub', '')]);

  	sub_timeout[$(this).attr('id').replace('_sub', '')] = window.setTimeout(function() { menu_out($(_self).attr('id').replace('_sub', ''), true); }, 10);
	});

	$('div.menu_items img').each( function() { $(new Image()).attr('src', $(this).attr('src').replace('.gif', '_over.gif')) });
	$('input[src]').each( function() { $(new Image()).attr('src', $(this).attr('src').replace('.gif', '_over.gif').replace('.png', '_over.png')) });

	$('div.pager a img.page').each( function() {
		$(new Image()).attr('src', $(this).attr('src').replace('.gif', '_over.gif'));
	});

	$('div.pager a img.page').mouseover( function() {
		$(this).attr('src', $(this).attr('src').replace('.gif', '_over.gif'));
	});

	$('div.pager a img.page').mouseout( function() {
		$(this).attr('src', $(this).attr('src').replace('_over.gif', '.gif'));
	});

	$('div.arrow_back img').mouseover( function() {
		$(this).attr('src', $(this).attr('src').replace('.gif', '_over.gif'));
	});

	$('div.arrow_back img').mouseout( function() {
		$(this).attr('src', $(this).attr('src').replace('_over.gif', '.gif'));
	});

	$('div.arrow_back img').click(function() { history.back() });

	$(new Image()).attr('src', 'images/popup_close_over.gif');
	
	$('img#jqiclose').live('mouseover', function() {
		$(this).attr('src', $(this).attr('src').replace('.gif', '_over.gif'));
		$(this).attr('src', $(this).attr('src').replace('.png', '_over.png'));
	});

	$('img#jqiclose').live('mouseout', function() {
		$(this).attr('src', $(this).attr('src').replace('_over.gif', '.gif'));
		$(this).attr('src', $(this).attr('src').replace('_over.png', '.png'));
	});
});
