//jquery.function.js

//----------JQUERY-FUNCTION----------//

var bannerClearTime;
var bannerSetTime;

$(document).ready(

function() {
	
	$(".add_cena_checked").click (
	function() {
		var cena_id = $(".search_left_links p a").index(this); 
		var id = $(this).attr("id").split(";");
		
		$("#cena_od").attr({value: id[0]});
		$("#cena_do").attr({value: id[1]});		
		
		document.search_left_form.submit();
	});
	
	$(".delete_input_checked").click (
	function() {
		$(this).parent(".search_left_main_select").children("input").removeAttr("checked");
		
		document.search_left_form.submit();		
	});
	
	$(".delete_cena_checked").click (
	function() {
		$("#cena_od").attr({value: ""});
		$("#cena_do").attr({value: ""});		
		
		document.search_left_form.submit();
	});
	
	$(".desc_back").mouseover(
	function() {
		$(this).css({background:"#18a7e1",color:"#fff"});
	});
	
	$(".desc_back").mouseout(
	function() {
		$(this).css({background:"#ffffff",color:"#032140"});
	});
	
	$(".desc_back_1").mouseover(
	function() {
		$(this).css({background:"#18a7e1",color:"#fff"});
	});
	
	$(".desc_back_1").mouseout(
	function() {
		$(this).css({background:"#f5f5f5",color:"#032140"});
	});

			
	$(".button_active").mouseover(
	function() {
		var img_src = $(this).attr("src").split(".");
		var img_check = img_src[0].split("-");
		
		if (img_check[1]!="1") {
			var img_src_new = img_src[0]+"-1."+img_src[1];
			
			$(this).attr({src: img_src_new});	
		}
	});
	
	$(".button_active").mouseout(
	function() {
		var img_src = $(this).attr("src").split(".");
		var img_check = img_src[0].split("-");
		
		if (img_check[1]=="1") {
			var img_src_new = img_check[0]+"."+img_src[1];
			
			$(this).attr({src: img_src_new});	
		}
	});
	
	//-----banner-show-switch-----//
	if ($("#notebookmarket_baner_start").is(":visible")) {bannerBox();}
	
	$(".notebookmarket_baner_switch_01 a").click(
	function()
	{
		bannerClearTime = clearTimeout(bannerSetTime);
	  		
	  	var index = $(".notebookmarket_baner_switch_01 a").index(this);
	  	var length = $(".notebookmarket_baner_switch_01 a").length;
	  	
	  	//check-visible
		for (var i=0; i<length; i++) 
		{
			if ( $("#notebookmarket_baner_main a").eq(i).is(":visible") ) 
			{
				var indexPrev = i;
					
				//check-index
				if ( indexPrev == length-1 ) 
				{
					var indexNext = 0;
				} 
				else 
				{
					var indexNext = indexPrev + 1;
				}
			}
		}
				
		var image_prev = "images/icons/banner_switch_"+(indexPrev+1)+".jpg";
		var image_next = "images/icons/banner_switch_"+(index+1)+"-1.jpg";
		
		$("#notebookmarket_baner_main a").css({display: "none"});
	  	$(".notebookmarket_baner_switch_01 a").eq(indexPrev).removeClass("notebookmarket_baner_switch_active");
	  	$(".notebookmarket_baner_switch_01 a img").eq(indexPrev).attr({src: image_prev});
	  	
	  	$("#notebookmarket_baner_main a").eq(index).css({display: "block"});
	  	$(".notebookmarket_baner_switch_01 a").eq(index).addClass("notebookmarket_baner_switch_active");
	  	$(".notebookmarket_baner_switch_01 a img").eq(index).attr({src: image_next});
	  	
	  	bannerBox();
	});
	  	
	//-----banner-show-stop-----//
	$("#notebookmarket_baner_main a").mouseover(
	function()
	{
		bannerClearTime = clearTimeout(bannerSetTime);
	});
	  	
	//-----banner-show-start-----//
	$("#notebookmarket_baner_main a").mouseout(
	function()
	{
		bannerBox();
	});	
});

//----------FUNCTION----------//
function bannerBox()
{
	if ( $("#notebookmarket_baner_start").is(":visible") ) {	
		var length = $(".notebookmarket_baner_switch_01 a").length;
	
		if (length>1) {
			bannerSetTime=setTimeout(function(){ bannerSet(); }, 4000);
		}
	}
}

//-----banner-set-----//
function bannerSet() 
{
	bannerClearTime = clearTimeout(bannerSetTime);
	var count = $("#notebookmarket_baner_main a").length;
		
	//check-visible
	for (var i=0; i<count; i++) 
	{
		if ( $("#notebookmarket_baner_main a").eq(i).is(":visible") ) 
		{
			var indexPrev = i;
				
			//check-index
			if ( indexPrev == count-1 ) 
			{
				var indexNext = 0;
			} 
			else 
			{
				var indexNext = indexPrev + 1;
			}
		}
	}
	
	var image_prev = "images/icons/banner_switch_"+(indexPrev+1)+".jpg";
	var image_next = "images/icons/banner_switch_"+(indexNext+1)+"-1.jpg";
	
	$("#notebookmarket_baner_main a").eq(indexPrev).fadeOut("slow", function() {
		$("#notebookmarket_baner_main a").eq(indexNext).fadeIn("slow");
		//alert("aaa");
	});	
	
	$(".notebookmarket_baner_switch_01 a").eq(indexPrev).removeClass("notebookmarket_baner_switch_active");
	$(".notebookmarket_baner_switch_01 a img").eq(indexPrev).attr({src: image_prev});
	  	
	$(".notebookmarket_baner_switch_01 a").eq(indexNext).addClass("notebookmarket_baner_switch_active");
	$(".notebookmarket_baner_switch_01 a img").eq(indexNext).attr({src: image_next});
	
	bannerBox();
}


