
var anidone=true;
var running = true;
var currentitem=0;
var intervalid=-1;

function autoswapnav()
{
	if(running)
	{
		prev = currentitem;
		currentitem++;
		if (currentitem ==5)
			currentitem = 0;
		
		swapnav(currentitem, prev);
	}
}


function stopit()
{
	running=false;
	clearInterval(intervalid);
}

function startit()
{
	var ids = ["#swname-0", "#swname-1","#swname-2","#swname-3","#swemail-0","#swemail-1","#swemail-2","#swemail-3", "#swemail-9"];
	
	for (i in ids)
	{
		$(ids[i]).focus( function(event) {
				//alert('wtf');
				stopit();
			//	document.write('md');	
			$(this).unbind(event);
			//	$(this).unbind('focus');
			});
	}
	
//	$('#swname-0').
		
	
	
	intervalid = setInterval('autoswapnav()', 20000);
	running=true;
	
}

function swapnav(itemnum, prev)
{	
	if (anidone==true)
	{
		anidone = false;
		$("#selecteditem-" + prev).customFadeOut("fast"	
		, function()
				{
					$("#selecteditem-" + itemnum).customFadeIn("fast");
					
					$("#selector-" +itemnum).addClass('selected');
					$("#selector-" +(prev)).removeClass('selected');
					
					/*$("#so-" + itemnum).html($("#theoffer").html());*/
					$("#so-"+itemnum).addClass('specialoffer');
					$("#so-"+itemnum).addClass('sohome');
					anidone=true;
				}
		);
		
		/*$("#convertimage").addClass("convertimage-" + itemnum);
		$("#convertimage").removeClass("convertimage-" + (itemnum-1));
		$("#convertimage").removeClass("convertimage-" + (itemnum+1));
		$("#convertdiv").html($("#convertdiv-" + itemnum).html());
		$("#selector-" + (itemnum-1)).removeClass('selected');
		//alert(itemnum);*/
		
	//}
	}
	else
	{
		//alert('not finished');
	}

}

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

google.setOnLoadCallback(function() {
  $(function() {
	

	  
	  $(document).ready(function() {
		  
		  
		  $("#searchform").submit(function(event) {
			  bStop = false;
			  if ($("#s").val() == 'Enter Keywords')
			  	bStop = true;
			  	
		  
		  		if(bStop)
		  		{
		  		
		  			event.preventDefault();
		  			$("#s").focus();
		  			 return false;
		  		}
		  		
		  		
			 
		  });
		 //create div
		 //set background
		 //fade it in
		  /* create background gradient */
		  var height = $("#container").height() -30;
		  $("#newdiv").height(height);
		  $("#newldiv").height(height);
		  $("#newrdiv").height(height);
		  
		  //.setAttribute('style', 'height: ' + height);
		  /*d2 = document.createElement("div");
		  d2.setAttribute('id', 'newdiv');
		  d2.setAttribute('style','z-index:-2;left:0;background:red;margin-top:15px;margin-bottom:15px;position:absolute;border:0px;display:none;height:'+ height + 'px;width:100%;');
		  d2.setAttribute('class','thegrad2');
		  
		  $("#container").append(d2);
		  
		  
		  
		  d2 = document.createElement("div");
		  d2.setAttribute('id', 'newldiv');
		  d2.setAttribute('style','z-index:-1;margin-top:15px;margin-bottom:15px;position:absolute;border:1;display:none;height:'+ height + 'px;width:15px;');
		  
		  d2.setAttribute('class','theothergrad');
		  $("#container").append(d2);
		  
		  d2 = document.createElement("div");
		  d2.setAttribute('id', 'newrdiv');
		  d2.setAttribute('style','z-index:-1;margin-top:15px;margin-left:965px;margin-bottom:15px;position:absolute;border:1;display:none;height:'+ height + 'px;width:15px;');
		  d2.setAttribute('class','theothergrad');
		  $("#container").append(d2);
		  
		  */
		  $("#newdiv").customFadeIn('slow');
		  $("#newldiv").customFadeIn('slow');
		  $("#newrdiv").customFadeIn('slow');
		  //document.write('<div id="yourdiv" style="display:none;height:'+height+'px;width:100%;"></div>');

		 if ($("#selector").length >0)
		 {
			 setTimeout('startit()', 2000);
		
		 
		//  $('#swname-1').blur( stopit());
		//  $('#swname-2').blur( stopit());
		//  $('#swname-3').blur( stopit());
		  
		  $('#selector li').click( function () {
			  
			  
			  s = $('#selector li.selected').attr('id');
			  
			  if (s)
			  {
				  s = s.substr(s.length-1,1);
			  
				  t =$(this).attr('id');
				  if (t)
				  {
					  t = t.substr(t.length-1, 1);
					  if (s!=t)
					  {
					  
						  stopit();
						  swapnav(t,s);
						  currentitem = t;
					  
					  
					  }
				  }
			  }
			 
			  //$(this).attr('id').substr()
			  
			  //alert(substring(($(this).attr('id')($(this).attr('id').length));
			  //alert(t);
			  //swapnav()
		  });
	
		  
		  

			  
			  $("#controllerright a").click( function () {
	
				  	//alert(currentitem);
					
					i= currentitem;
				  currentitem++;
					if (currentitem ==5)
						currentitem = 0;
				stopit();
				 swapnav(currentitem, i);
				  return false;
			  });
			  
	  			$("#controllerleft a").click( function () {
	  				i = currentitem;
	  				currentitem--;
	  				
					if (currentitem == -1)
						currentitem = 4;
					stopit();
	  				swapnav(currentitem, i);
	  				return false;
	  			});
		 }
		//alert('done');
		  
	  });
    // init my stuff
  });
  
});



	
