$(document).ready(function(){
  $.preloadImages('btn_ajanlo_act.jpg', 'btn_cancel_act.jpg', 'btn_dehibernate_act.jpg', 'btn_delete_act.jpg',
    'btn_edit_act.jpg', 'btn_felhasznalok_act.jpg', 'btn_jatekter_act.jpg', 'btn_keresek_act.jpg',
    'btn_login_act.jpg', 'btn_logout_act.jpg', 'btn_nav_adatok_act.jpg', 'btn_nav_barataim_act.jpg',
    'btn_nav_barataim_act.jpg', 'btn_nav_beallitasok_act.jpg', 'btn_nav_helpdesk_act.jpg',
    'btn_nav_kijelentkezes_act.jpg', 'btn_nav_leveleim_act.jpg', 'btn_nav_meghivok_act.jpg',
    'btn_nav_torrentjeim_act.jpg', 'btn_ok_act.jpg', 'btn_save_act.jpg', 'btn_send_act.jpg', 'btn_show_act.jpg',
    'btn_signup_act.jpg', 'btn_testit_act.jpg', 'btn_top10_act.jpg', 'btn_upload_act.jpg', 'btn_vote_act.jpg',
    'box_opener_act.jpg', 'box_head_left_closed.jpg', 'box_opener_close.jpg', 'box_opener_close_act.jpg',
    'box_head_right_closed.jpg', 'head_navi_openbtn_down_act.jpg', 'head_navi_openbtn_up_act.jpg',
    'mailbutton_level_irasa_act.jpg', 'mailbutton_postalada_act.jpg', 'mailbutton_postazott_levelek_act.jpg',
    'mailbutton_szemetkosar_act.jpg');
  //*** header hide *************************************************************************
  if(states.GetItem("header") == 1){
    $('#headerSlide').hide();
  }
	//*** dom wrappers ************************************************************************
	$('.box').each(function(){
		if($(this).attr('rel') == 'closed' || states.GetItem($(this).attr('id')) == 1){
      $(this).children('.content,.contentInfo,.footer').hide();
    	$(this).children('.header').css('background-image','url(themes/'+theme+'/box_head_left_closed.jpg)');
    	$(this).children('.control').css('background-image','url(themes/'+theme+'/box_opener_close.jpg)');
    	$(this).children('.right').css('background-image','url(themes/'+theme+'/box_head_right_closed.jpg)');
    }
	});

	//*** IE6 png fix *************************************************************************
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if(badBrowser) {
   	$('img[src$=.png]').each(function() {
			if(!this.complete) {
				this.onload = function() { fixPng(this) };
			} else {
				fixPng(this);
			}
		});
   }

   //*** IE6 radio and checkbox background fix **********************************************
   $('input[@type=radio],input[@type=checkbox]').each(function() {
		$(this).css('border-width','0px');
		$(this).css('background-color','transparent');
		$(this).css('background-image','none');
	});

	//*** header flash *************************************************************************
	if($.id('headerFlash') && !$('#headerFlash').hasClass('noflash')){
	  	var so = new SWFObject('themes/'+theme+'/header.swf','headerFlash','995','219','9','#000000');
	  	so.addVariable('allowScriptAccess','sameDomain');
	  	so.write('headerFlash');
	}

	//*** button mouseover *************************************************************************
	$('#buttons a,#bHeaderOpen,#bHeaderClose,#mailbox a,.bSubmit,.bCancel,.bHiber,.bDelete,.bEdit,.bLogin,.bLogout,.bOk,.bSave,.bSend,.bReg,.bTest,.bUpload,.bVote').each(function() {
		$(this).mouseover(function() {
			$(this).css('background-image',$(this).css('background-image').replace(/\.jpg/,'_act.jpg'));
		});

		$(this).mouseout(function() {
			$(this).css('background-image',$(this).css('background-image').replace(/_act\.jpg/,'.jpg'));
		});
	});

  // gotmail
  if(newmails){
    $('#bMails').css('background-image', $('#bMails').css('background-image').replace(/\.jpg/,'_act_red.jpg'));
    $('#bMails').unbind('mouseover');
		$('#bMails').unbind('mouseout');
  }

	//*** rating *************************************************************************
	var ratingWidth = $('#ratingBar').css('width');
	$('#ratingBar').css('width','347px');
	$('#ratingBar').append('<div id="ratingBarLineStart"></div><div id="ratingBarLine"></div><div id="ratingBarLineEnd"></div><br class="clear" />');
	$('#ratingBarLine').css('width',ratingWidth);

	//*** forum *************************************************************************
	$('.forum tr td').each(function() {
		/*$(this).css('float','left'));*/
	});


	//*** header slide *************************************************************************
	$('#bHeaderClose').click(function() {
		  if($('#headerSlide').is(":visible")){
  			$('#headerSlide .welcome').fadeOut('slow',function() {
  				$('#headerSlide').slideUp('slow');
  				states.SetItem("header", 1);
  			});
			}
	});
	
	$('#bHeaderOpen').click(function() {
		  if($('#headerSlide').is(":hidden")){
  			$('#headerSlide').slideDown('slow',function() {
  				$('#headerSlide .welcome').fadeIn('slow');
  				states.SetItem("header", null);
  			});
			}
	});

	//*** box slide *************************************************************************
	$('.box .control').each(function() {
		$(this).mouseover(function() {
			$(this).css('background-image',$(this).css('background-image').replace(/\.jpg/,'_act.jpg'));
		});

		$(this).mouseout(function() {
			$(this).css('background-image',$(this).css('background-image').replace(/_act\.jpg/,'.jpg'));
		});

		$(this).click(function() {
			if($(this).parent().children('.footer').is(":hidden")){
				$(this).parent().children('.footer').show();
				$(this).parent().children('.header').css('background-image','url(themes/'+theme+'/box_head_left.jpg)');
  			$(this).parent().children('.control').css('background-image','url(themes/'+theme+'/box_opener.jpg)');
  			$(this).parent().children('.right').css('background-image','url(themes/'+theme+'/box_head_right.jpg)');
				$(this).parent().children('.content,.contentInfo').slideDown('slow', function(){
				  states.SetItem($(this).parent().attr('id'), null);
				});
			}else{
				states.SetItem($(this).parent().attr('id'), 1);
				$(this).parent().children('.content,.contentInfo').slideUp('slow', function(){
					$(this).parent().children('.footer').hide();
					$(this).parent().children('.header').css('background-image','url(themes/'+theme+'/box_head_left_closed.jpg)');
					$(this).parent().children('.control').css('background-image','url(themes/'+theme+'/box_opener_close.jpg)');
					$(this).parent().children('.right').css('background-image','url(themes/'+theme+'/box_head_right_closed.jpg)');
			  });
			}
		});
	});
});

function fixPng(png) {
	var src = png.src;

	if(!png.style.width) {
		png.style.width = $(png).width();
	}
	if(!png.style.height) {
		png.style.height = $(png).height();
	}

	png.onload = function() { };
	png.src = blank.src;

	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}