// JavaScript Document
$(document).ready(function() {

 function findValue(li) { 
//if( li == null ) return alert("אין תוצאות!"); 
// if coming from an AJAX call, let's use the CityId as the value 
if( !!li.extra ) var sValue = li.extra[0]; 
// otherwise, let's just display the value in the text box 
else var sValue = li.selectValue; 
//alert("The value you selected was: " + sValue); 
$("form[action='/Search/']").submit();

} 

function selectItem(li) { 
findValue(li); 
}
 
function formatItem(row) { 
return row[0] //+ " (id: " + row[1] + ")"; 
} 

function lookupAjax(){ 
var oSuggest = $("#CityAjax")[0].autocompleter; 
oSuggest.findValue(); 
return false; 
} 

function lookupLocal(){ 
var oSuggest = $("#CityLocal")[0].autocompleter; 
oSuggest.findValue(); 
return false; 

} 
	$("#CityAjax").autocomplete(

		"includes/autocomplete.php",
		{
			delay:10,
			minChars:3,
			matchSubset:1,
			matchContains:0,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			autoFill:false
		}
    );
	
	$(".GSMI img").click(function() {
		var src = $(this).attr("src");
		var alt = $(this).attr("alt");
		var title = $(this).attr("title");
		$(".GBIG img").attr("src",src);
		$(".GBIG img").attr("alt",alt);
		$(".GBIGD").text(title);
	});
	
	
	$(".CONOT").click(function() {

		var e = $(this).next(".CKNONE");
		/*var boxHeight = '389';
		if(e.css('display') !== 'block'){
		
			e.height('0');
			e.css('display','block');
			e.animate({height:boxHeight},500);
		
		}else if(e.css('display') == 'block'){
		
			e.animate({height:0},500,function(){
			e.css('display','none');
			});
			
			}
		*/
	e.slideToggle(500);		
	});
	
	
	
	

	var i_width = $(".NBOX").width();
	
		var counter = 3;
		
		var countx = $(".ISCROLLH").length;

		for(i=0;i<countx;i++){
		
		$(".ISCROLLH").eq(i).children(".NBOX").eq(counter-1).addClass("active");
			var items = $(".ISCROLLH").eq(i).children(".NBOX").length;
			if(items<=3){
			
					$(".ISCROLLH").eq(i).parent().siblings(".ILEFT").css('display','none');
					$(".ISCROLLH").eq(i).parent().siblings(".IRIGHT").css('display','none');
					
			}
		}
		
		
	$(".ILEFT").css("display","none");
	var items = $(".NBOX").length;
	$(".ISCROLLH").css('width',(items*(i_width + 20))+'px');
	//$(".ISCROLLH").css('width','2000px');

	$(".ILEFT").live('click',function() {	

			var index = $(this).prev(".ISCROLC").children(".ISCROLLH");
			var items = $(this).prev(".ISCROLC").children(".ISCROLLH").children(".NBOX").length;			
			counter = $(this).prev(".ISCROLC").children(".ISCROLLH").children(".active");
		if (counter.index() > 2) {

			index.animate({'left':'+=231px'},400);
			counter.prev(".NBOX").addClass("active");
			counter.removeClass("active");
			$(this).next().css("display","inline");
			
			if(counter.index() > 3)
			$(this).css("display","inline");
			else
			$(this).css("display","none");
			
		} else {
			$(this).css("display","none");	
		}
		
	});
	
	$(".IRIGHT").live('click',function() {
			var items = $(this).prev().prev(".ISCROLC").children(".ISCROLLH").children(".NBOX").length;	
			var index = $(this).prev().prev(".ISCROLC").children(".ISCROLLH");			
			counter = $(this).prev().prev(".ISCROLC").children(".ISCROLLH").children(".active");
		if (counter.index() < Number(items-1)) {	

			index.animate({'left':'-=231px'},400);
			counter.next(".NBOX").addClass("active");
			counter.removeClass("active");
			$(this).prev().css("display","inline");
			
		if(counter.index() == items-2){
		$(this).css("display","none");
		}
		
		} else {
			$(this).css("display","none");	
		}
		
	});
	
	//counter++;
	
	$("#IBRIMG ul li").live('click',function(){

	if($(this).children("a").attr("href")){

		window.location = $(this).children("a").attr("href");
	
	}
});
var intervalA ;
function Interval(b,e,h,s){
if(b == true){
intervalA = setInterval(function (){$(e).trigger(h);}, s);
}else{
clearInterval(intervalA);
}
}

$(window).bind('load', function() { 	
	$(".svw").slideView();
	Interval(true,"#IBRIMG","focusout","5000");
});

$(".INAV").live('click',function(){
	Interval(false);
	$("#IBRIMG").trigger('focusout');
	Interval(true,"#IBRIMG","focusout","5000");
}); 

if($.browser.webkit){

$(window).bind('focus', function() { 	
	Interval(true,"#IBRIMG","focusout","5000");
});	

$(window).bind('blur', function() { 	
	Interval(false);
});		

}
/*
		$.post("includes/events.php",{month: month , year: year}, function(data) {
			$(".ELT").html(data);
		});*/
});
