$(document).ready(function(){

   $("#ebcontainer > table").css("margin","0 auto");//center form table
	
   $(".inputBox").focus(function(){
	   $(this).removeClass("inputBox");
	   $(this).addClass("inputFocus");
	});
   $("#recipeInput").focus(function(){
	   $(this).attr("value","");
	   $(this).removeClass("inputBox");
	   $(this).addClass("inputFocus");	   
	});   
   $(".headerR > form").submit(function(){
   	 var keyword = $("#inputBox").val();
	 if(keyword !="" && keyword!='enter keywords' && this.q.value.replace(/\s+/, '')){
	 	 return true;
	 }else{
	 	 return false;
	 }
   });
   
   $(".searchKeyword > form").submit(function(){
   	 var keyword = $("#recipeInput").val();
	 if(keyword !="" && keyword!='Search Recipes' && this.q.value.replace(/\s+/, '')){
	 	 return true;
	 }else{
	 	 return false;
	 }
   });

   $(".arbitrage ul").mouseover(function(e){
   	 $(e.target).closest("li:not(.noresult)").toggleClass("over");	 
   }).mouseout(function(e){
   	 $(e.target).closest("li:not(.noresult)").toggleClass("over");
   }); 
   
   $(".plus").click(function(e){
	   if(e.target.className=="plus"){
		 $(this).addClass("disn");
		 $(this).next().removeClass("disn"); 
		 $(this).parent().children("ul").fadeIn("slow");
	   }else{
	     $(this).removeClass("disn"); 
		 $(this).next().addClass("disn");
		 $(this).parent().children("ul").hide("200");
	   }
   });
   
   $(".minus").click(function(e){
	   if(e.target.className=="minus"){
		 $(this).addClass("disn");
		 $(this).prev().removeClass("disn"); 
		 $(this).parent().children("ul").hide("200");
		   
	   }else{
	     $(this).addClass("disn");
		 $(this).prev().removeClass("disn"); 
		 $(this).parent().children("ul").fadeIn("slow");
	   }
   });
   
	$('ul.menu > li').mouseover(function(){
    var li = this;
    this.tm = setTimeout(
      function(){$(li).addClass('over').find('div.list').show()},
      500
    );
		$('ul.menu > li > .list').mouseover(function(){
			$(this).show();
		})
	}).mouseout(function(){
    if (this.tm) clearTimeout(this.tm);
		$(this).removeClass('over').find('div.list').hide();
		$(this).stop();
	});
	
	//$('.FeaturedTopics > ul').mouseover(function(){
		//$(this).addClass('over');
	//}).mouseout(function(){
		//$(this).removeClass('over');
	//});   
	
	//$('.WorththeRead > ul').mouseover(function(){
		//$(this).addClass('over');
	//}).mouseout(function(){
		//$(this).removeClass('over');
	//});   

   if($("#banner").length>0){
	   	$(function () {
		  var img = new Image();
		  images = new Array();		  
		  img.src="images/loader.gif";		
		
		for(a=1;a<=5;a++){
		var finish;
		finish = 0;
			$(img).load(function(){	 			
				$('.loading').addClass('disn');
				finish = finish +1;				
				if(finish==5){
				change_img()
			   }	
	 		}).attr('src', 'images/banner/banner'+ a +'.jpg');		
				
		  } 
			
	   });		
	  

	   
   } 
   

   
 });


var nn;
nn=1;
function setFocus(i){
	  nn = i;
	  getBanner(nn);
  
}

function getBanner(id){
	prev = id - 1;
	next = id + 1;
	//alert(id);
	 if(id==1){
	   document.getElementById('page').innerHTML =' <strong class="prev">prev</strong><a href="#" onclick="javascript:setFocus('+ next  +');return false;" class="next">next</a>';
	 }else if(id==5){
	   document.getElementById('page').innerHTML =' <a href="#" onclick="javascript:setFocus('+ prev  +');return false;" class="prev">prev</a><strong class="next">next</a>'; 
     }else{
	   document.getElementById('page').innerHTML =' <a href="#" class="prev" onclick="javascript:setFocus('+ prev  +');return false;" class="prev">prev</a><a href="#" onclick="javascript:setFocus('+ next  +');return false;" class="next">next</a>'; 
	 }		
	 for(var i =1; i<=5; i++){
	   if(i == id){
		 document.getElementById('state'+ i).innerHTML = '<span onclick="javascript:setFocus('+ i +'); return false;" class="current"></span>';		
		 $("#banner"+i).fadeIn("700").removeClass("elseBanner");
		 $("#text"+i).show();
	   }else{
		 document.getElementById('state'+ i).innerHTML = '<span onclick="javascript:setFocus('+ i +'); return false;" class="normal"></span>';
		 $("#banner"+i).fadeOut("700").addClass("elseBanner");
		 $("#text"+i).hide();
	   }
	 }
}
//var calltimes = 0;
function change_img(){
	//calltimes = calltimes + 1;
	//if (calltimes >= 5) {
		//alert(nn);
		if (nn > 5) 
			nn = 1;
		getBanner(nn);
		nn++;
		tt = setTimeout('change_img()', 4000);
	//} 
}




