var mega_reload = true;

function changeCheck(el)
	/* 
		     
		el - span    
		input - 
	*/
	{
		 var el = el,
			  input = el.find("input").eq(0);
		 if(!input.attr("checked")) {
			el.css("background-position","0 -13px");	
			input.attr("checked", true)
		} else {
			el.css("background-position","0 0");	
			input.attr("checked", false)
		}
		 return true;
	}
	

	function changeCheckStart(el)
	/* 
		   checked,   
	*/
	{//alert('t');
		var el = el,
		input = el.find("input").eq(0);
		
		if(input.attr("checked")==true) 
		{
			//alert(input.attr("checked"));
			el.css("background-position","0 -13px");	
		}
		else
		{
			el.css("background-position","0 0");	
		}
		return true;
	}
	
// JavaScript Document
$(document).ready(function()
{
	$('.scroll-pane').jScrollPane({
	showArrows: true	
	});
	
		
	/*~~~~    ~~~~*/
	$('#changeLink').click(function(){
		$('#changeBox').toggle();
		return false;
	})
	
	$('#changeBox ul li a').click(function(){
		$('#changeBox').toggle();
		$('#megaCity').text($(this).text());
		$('#megaCity').css({'color':'red'});
		$('#mega_port').load('/task/mega.php?id='+this.rel, 
				function(d){ 
					$('#megaCity').css({'color':'white'});
					if(mega_reload)
						window.location.reload(true);
				});
		return false;
	})
	/*~~~~ /   ~~~~*/
	
	/*~~~~  .  ~~~~*/
	$('.level1 > li').bind('mouseover', jsddm_open);
	$('.level1 > li').bind('mouseout',  jsddm_timer);
	/*~~~~ / .  ~~~~*/	
	
/*~~~  checkbox ~~~*/
	/* при клике на чекбоксе меняем его вид и значение */
	$(".niceCheck").mousedown(function() {
		 changeCheck($(this));
	});
	
	/* при загрузке страницы нужно проверить какое значение имеет чекбокс и в соответствии с ним выставить вид */
	$(".niceCheck").each(function() {
    	changeCheckStart($(this));
	});
/*~~~ / checkbox ~~~*/
     
	/*~~~    ~~~*/
	$('.mm').click(function(){
		$('.onMainCheck').attr('checked', false);
		$(this).find('.onMainCheck').attr('checked', true);
		
		$(".niceCheck").each(function() 
		{
    		changeCheckStart($(this));
		});
	})
	/*~~~ /   ~~~*/
	
	/*~~~    look ~~~*/
	$('.labelCheck, .niceCheck').click(function(){
		if($(this).parents('.top10Item').find('.labelCheck').is(":checked"))
		{
			$(this).parents('.top10Item').find('.megaLookLabel').removeClass('labelHide').addClass('labelShow');			
		}
		else
		{
			$(this).parents('.top10Item').find('.megaLookLabel').removeClass('labelShow').addClass('labelHide');
		}
	})
	/*~~~ /   look ~~~*/
	
	/*~~~      ~~~*/
	$('.submitBut').click(function(){
		//alert($(this).parents('.top10Item').find('form').html());
		$(this).parents('.top10Item').find('form').submit();	
	})		

/*	
	$(".top10Item form").submit(function(){
	 	$(this).ajaxSubmit({
			target: $(this).parents('.top10Item').find('.tt')
		});
		$(this).parents('.top10Item').find('.t').css('display', 'none');
		return false;
	});
*/
	/*~~~ /     ~~~*/
	
	/*~~~ popup ~~~*/
	$("a.commentButton").fancybox({
		'hideOnContentClick': true,
		'showCloseButton' : false,
		'autoDimensions' :false,
		'width' : 700
	});
	
	$("a.voitingButton").fancybox({
		'hideOnContentClick': false,
		'showCloseButton' : false,
		'autoDimensions' :false,
		'width' : 700
	});
	
	$('.no').click(function(){
		$.fancybox.close();						
	})
	/*~~~ popup ~~~*/	
    
    $('#loginFormLogin').click(function(){
		if($(this).attr('value') == 'email')
		{
			$(this).attr('value', '');
		}
	})
	$('#loginFormPwd').click(function(){
		if($(this).attr('value') == 'pwdpwd')
		{
			$(this).attr('value', '');
		}
	})
    
    var srchValue = $('#srch').attr('value');
    $('#srch').click(function(){
		if($(this).attr('value') == srchValue)
		{
			$(this).attr('value', '');
		}
	})
	
});

