
$(function(){
		   /*
		   var t = '[{';
		   var i=$(".search").lenght;
		   $(".search").each(function(){
		   t+='\'date\':\''+$(this).attr("date")+'\'';
		    i--;
		   if(i!=0){
			   t+=',';
			   }
			})
		   
			t+= '}];';
*/
		  // var t =eval(t);
		   //alert(t[0].date);
//calendar
$('#inputDate8').datePicker({inline:true,renderCallback:function($td, thisDate, month, year){
							 $(".search").each(function(){
														//alert(thisDate.getDate()+'-'+parseInt(parseInt(month)+1)+'-'+year);
														//alert($(this).attr('date'));
														var m = parseInt(parseInt(month)+1);
															if(parseInt(m)<10){
															m='0'+m;
															}
								if($(this).attr('date')==thisDate.getDate()+'-'+m+'-'+year){
								$td.css({'background-color':'#FF9900', 'font-weight':'bold'});
								}
							  })
							  }
							}).bind('dateSelected',function(e, selectedDate, $td){godate(selectedDate.asString())});






$("img").each(function(){
$(this).css({'margin':'0px'});

})

	$(".img").fadeTo("fast",0.6);
	
	
	
        //$('.content a[rel=lightbox]').lightBox();
   
	$("div[h=m]").each(function(){
		$(this).css({'opacity':'0','display':'block'});
	})


$(".img").hover(function () {

	if (parseInt($(this).css('opacity')) != 0.8) {

		

		$(".img").fadeTo("fast", 0.6);
		
		$("div[h=m]").each(function(){
			$(this).fadeTo("fast", 0);//slideUp("fast");
			
		});
	}
      $(this).fadeTo("fast", 1);
	  $(".img_"+$(this).attr("id")).fadeTo("fast", 0.8);//slideDown("fast");

   },function(){
	 
	})

	
	
	//if(parseInt($("#list").width())>=768){
		$("#controls").after('<div  style="position:absolute; z-index:9"><a href="#"><div id="left" onmouseover="on_mouse_over_right(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/left_a.gif)\'});" onmouseout="on_mouse_out(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/left.gif)\'});" style="position: relative; cursor:hand; width:57px; height:30px; top: 290px;background-image: url(http://'+top.location.host+'/images/left.gif);background-repeat: no-repeat;">&nbsp;</div></a><a href="#"><div id="right" onmouseover="on_mouse_over_left(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/right_a.gif)\'});" onmouseout="on_mouse_out();$(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/right.gif)\'})" style="position: relative; cursor:hand; width:57px; height:30px; left:758px; top: 258px; background-image: url(http://'+top.location.host+'/images/right.gif);background-repeat: no-repeat;">&nbsp;</div></a></div>');
		$("#controls2").after('<div style="position:absolute; z-index:9"><a href="#"><div id="left" onmouseover="on_mouse_over_right(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/left_a.gif)\'});" onmouseout="on_mouse_out(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/left.gif)\'});" style="position: relative; cursor:hand; width:57px; height:30px; top: 63px;background-image: url(http://'+top.location.host+'/images/left.gif);background-repeat: no-repeat;">&nbsp;</div></a><a href="#"><div id="right" onmouseover="on_mouse_over_left(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/right_a.gif)\'});" onmouseout="on_mouse_out(); $(this).css({\'background-image\':\'url(http://'+top.location.host+'/images/right.gif)\'})"  style="position: relative; cursor:hand; width:57px; height:30px; left:758px; top: 33px; background-image: url(http://'+top.location.host+'/images/right.gif);background-repeat: no-repeat;">&nbsp;</div></a></div>');
	//}
	
	$(".img[sub=fav],div[sub=fav]").click(function(){
		$.post("http://" + top.location.host + "/mods/request.php", {
			lang:$(this).attr('lang'),
			sub: "fav",
			target: $(this).attr('refresh'),
			id: $(this).attr('id')
		}, function(data){
			$("#refresh").html(data);
			$('.content a[rel=lightbox]').lightBox();
		})
	})
	
	$(".img[sub=off],div[sub=off]").click(function(){
		$.post("http://" + top.location.host + "/mods/request.php", {
			lang:$(this).attr('lang'),
			sub: "off",
			id: $(this).attr('id')
		}, function(data){
			$("#refresh").html(data);
			$('.content a[rel=lightbox]').lightBox();
		})
	})
	
		$(".img[sub=off_h],div[sub=off_h]").click(function(){
		$.post("http://" + top.location.host + "/mods/request.php", {
			lang:$(this).attr('lang'),
			sub: "off_h",
			id: $(this).attr('id')
		}, function(data){
			$("#refresh").html(data);
			$('.content a[rel=lightbox]').lightBox();
		})
	})
	
	$(".img[sub=proj],div[sub=proj]").click(function(){
		$.post("http://" + top.location.host + "/mods/request.php", {
			lang:$(this).attr('lang'),
			sub: "proj",
			id: $(this).attr('id')
		}, function(data){
			$("#refresh").html(data);
			$('.content a[rel=lightbox]').lightBox();
		})
	})
	
	$(".menuA[r=t]").hover(function(){
		$(this).css({'color':'#ff6600'});
	},function(){
		$(this).css({'color':'#ff9900'});
	});
	
	
	$(".menuA[r=y]").hover(function(){
		$(this).css({'color':'#ff6600'});
	},function(){
		$(this).css({'color':'#ff9900'});
	});
	
	$(".new").hover(function(){
		$(this).css({'color':'#ff6600'});
	},function(){
		$(this).css({'color':'#ff9900'});
	});
	
	
	$(".menuA[r=t]").click(function(){
		$("#s_"+$(this).attr('id')).hide();
		$("#l_"+$(this).attr('id')).show();
			$(this).css({'display':'none'});
			$(".menuA[r=tu][id="+$(this).attr('id')+"]").css({'display':'block'});
	})
	
	$(".menuA[r=tu]").click(function(){
		$("#s_"+$(this).attr('id')).show();
		$("#l_"+$(this).attr('id')).hide();
			$(this).css({'display':'none'});
			$(".menuA[r=t][id="+$(this).attr('id')+"]").css({'display':'block'});
	})
	
	$(".new").click(function(){
		$(this).css({'display':'none'});
		$(".newup[id="+$(this).attr('id')+"]").css({'display':'block'});
		$("#n_"+$(this).attr('id')).hide();
		$("#nl_"+$(this).attr('id')).show();
	})
	
	$(".newup").click(function(){
		$(this).css({'display':'none'});
		$(".new[id="+$(this).attr('id')+"]").css({'display':'block'});
		$("#n_"+$(this).attr('id')).show();
		$("#nl_"+$(this).attr('id')).hide();
	})
	
	



$("#theme,#city,#country").change(function(){

	/* KPI - RULET! PTCA - RULIT! TKACHENKO - RULIT! //?????? ??????? ?? ??????????? ?? ????? ????????? ? ???????, ????? ??
	 * t d c c
	 * 0 0 0 0 16
	 * 0 0 0 1 15
	 * 0 0 1 0 14
	 * 0 0 1 1 13
	 * 0 1 0 0 12
	 * 0 1 0 1 11
	 * 0 1 1 0 10
	 * 0 1 1 1 9
	 * 1 0 0 0 8
	 * 1 0 0 1 7
	 * 1 0 1 0 6 
	 * 1 0 1 1 5
	 * 1 1 0 0 4
	 * 1 1 0 1 3
	 * 1 1 1 0 2
	 * 1 1 1 1 1
	*/

        $(".search").hide();
		
        if ($("#theme").val() != '-' && $("#city").val() != '-' & $("#country").val() != '-') {//1111
            $(".search[theme=" + $("#theme").val() + "][city="+ $("#city").val()+"][country=]"+$("#country").val() ).show();
        }else 
		if($("#theme").val() != '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//1110
		 $(".search[theme=" + $("#theme").val() + "][city="+ $("#city").val()).show();
		}else 
		if($("#theme").val() != '-' && $("#city").val() == '-' & $("#country").val() != '-'){//1101
		 $(".search[theme=" + $("#theme").val() + "][country="+ $("#country").val()+"]" ).show();
		}else 
		if($("#theme").val() != '-'  && $("#city").val() == '-' & $("#country").val() == '-'){//1100
		 $(".search[theme=" + $("#theme").val() + "]" ).show();
		}else 
		if($("#theme").val() != '-' && $("#city").val() != '-' & $("#country").val() != '-'){//1011
		 $(".search[theme=" + $("#theme").val() + "][country=" + $("#country").val() + "][city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() != '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//1010
		 $(".search[theme=" + $("#theme").val() + "][city="+ $("#city").val()+"]").show();
		}else 
		if($("#theme").val() != '-'  && $("#city").val() == '-' & $("#country").val() != '-'){//1001
		 $(".search[theme=" + $("#theme").val() + "][country="+ $("#country").val()+"]" ).show();
		}else 
		if($("#theme").val() != '-'  && $("#city").val() == '-' & $("#country").val() == '-'){//1000
		 $(".search[theme=" + $("#theme").val() + "]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() != '-' & $("#country").val() != '-'){//0111
		 $(".search[country=" + $("#country").val() + "][city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//0110
		 $(".search[city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() == '-' & $("#country").val() != '-'){//0101
		 $(".search[country="+ $("#country").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-' && $("#city").val() != '-' & $("#country").val() != '-'){//0011
		 $(".search[country=" + $("#country").val() + "][city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//0010
		 $(".search[city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() == '-' & $("#country").val() != '-'){//0001	
		 $(".search[country="+ $("#country").val()+"]" ).show();
		}
        else {
                    $(".search").show();//0000
        }
  
})
		 
		 
function godate(date){
						
						
		var d = new Date();
		var m=parseInt(parseInt(d.getMonth())+parseInt(1));
		if(parseInt(m)<10){
			m='0'+m;
			}
		
		
		
		if(parseInt(d.getYear())<1900){
			var t = d.getDate()+'-'+m+'-'+parseInt(parseInt(d.getYear())+1900);
			}else{
			var t = d.getDate()+'-'+m+'-'+parseInt(parseInt(d.getYear()));
			}

		//alert(t);
		if(t==date){
			$(".search").show();
		}else{
		 $(".search").hide();
		
        if ($("#theme").val() != '-'  && $("#city").val() != '-' & $("#country").val() != '-') {//1111
            $(".search[theme=" + $("#theme").val() + "][date=" + date + "][city="+ $("#city").val()+"][country=]"+$("#country").val() ).show();
        }else 
		if($("#theme").val() != '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//1110
		 $(".search[theme=" + $("#theme").val() + "][date=" + date + "][city="+ $("#city").val()).show();
		}else 
		if($("#theme").val() != '-'  && $("#city").val() == '-' & $("#country").val() != '-'){//1101
		 $(".search[theme=" + $("#theme").val() + "][date=" + date + "][country="+ $("#country").val()+"]" ).show();
		}else 
		if($("#theme").val() != '-' && $("#city").val() == '-' & $("#country").val() == '-'){//1100
		 $(".search[theme=" + $("#theme").val() + "][date=" + date + "]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() != '-' & $("#country").val() != '-'){//0111
		 $(".search[country=" + $("#country").val() + "][date=" + date + "][city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() != '-' & $("#country").val() == '-'){//0110
		 $(".search[date=" + date + "][city="+ $("#city").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-'  && $("#city").val() == '-' & $("#country").val() != '-'){//0101
		 $(".search[date=" + date + "][country="+ $("#country").val()+"]" ).show();
		}else 
		if($("#theme").val() == '-' && $("#city").val() == '-' & $("#country").val() == '-'){//0100
		 $(".search[date=" + date + "]" ).show();
		}
		
		}
}


  })//end
  /*
function right(){
			var limit = parseInt($("#list").css("left"));
			if (limit <= 0) {
				if (limit <= 0 && limit >= -parseInt($("#list").width()) + 768) {
					$("#list").animate({
						left: limit - 100 + 'px'
					}, {
						queue: false,
						duration: 100
					})
				}
			}else{
				$("#list").css({"left":'0px'})
			}
			
		}
function left(){
			var limit = parseInt($("#list").css("left"));
			if (limit < 0) {
				$("#list").animate({
						left: limit + 100 + 'px'
					}, {
						queue: false,
						duration: 100
					})
			}
			
		}
	*/	
var run = 0;
var timer = 0;

function on_mouse_over_left()
{
    if (!run)
    {
        run = 1;
        timer = setInterval(on_timer_left, 10);
    }
}

function on_mouse_over_right()
{
    if (!run)
    {
        run = 1;
        timer = setInterval(on_timer_right, 10);
    }
}

function on_mouse_out()
{
    if (timer)
        clearInterval(timer);
    timer = 0;
    run = 0;
}

function on_timer_left()
{
   		var limit = parseInt($("#list").css("left"));
			if (limit <= 0) {
				if (limit <= 0 && limit >= -parseInt($("#list").width()) + 768) {
					$("#list").css({'left':limit - 4 + 'px'});
				}
			}else{
				$("#list").css({"left":'0px'})
			}
}
function on_timer_right()
{
   		
			var limit = parseInt($("#list").css("left"));
			if (limit < 0) {
				$("#list").css({'left':limit + 4 + 'px'});
				
			}
}

function on_click()
{
    if (timer)
        clearInterval(timer);
    timer = 0;
    run = 0;
    // do work...
}

function alld(){$(".search").show()};
