/*
author: surge interactive, inc.
email: dave@surgeinteractive.com
web: http://surgeinteractive.com
*/



function initPromos(){
	var promo=jQuery.url.param('promo');
	if(!promo){
		promo=0;
	}
	jQuery('#promotion-images').cycle({ 
					fx:     'fade', 
					speed:  'fast', timeout: 0,
					startingSlide: promo, // zero-based
					after:   function(){
	},
			pager:  '#promotionnavi', 
			pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#promotionnavi a:eq(' + idx + ')'; 
			} 
	});
	jQuery('#promonaviloading').fadeOut(500,function(){
			jQuery('#promotionnavi').fadeIn('fast'); 
	});
}


function initMenu(){
		jQuery(".menunavilink").click(function(){
			jQuery(".menunavilink").each(function(){
				var src=jQuery(this).children().attr("src").replace("_on","_off");
				jQuery(this).children().attr("src",src);
			});
			var src=jQuery(this).children().attr("src").replace("_off","_on");
			jQuery(this).children().attr("src",src);
		 var targetdiv=jQuery(this).attr("rel");
			jQuery("#menunaviinfotext").hide();
			jQuery("#menunavicontent div").hide();
			jQuery("#"+targetdiv).fadeIn();
			return false;
	});
	jQuery("#menunavi-dinner a,#menunavi-drinks a,#menunavi-late_night a").click(function(){
		var targeturl=jQuery(this).attr("href");
		jQuery("#menunavicontent a").css("text-decoration","none");
		jQuery(this).css("text-decoration","underline");
	 jQuery.ajax({
  url: targeturl,
  success: function(data) {
			 jQuery(".menuright").fadeOut('fast',function(){jQuery(".menuright").html(data).fadeIn('fast',function(){jQuery(".tab6 a").trigger("click");});});
  }
	});		return false;

	});
}

function initEventTypes(){
	jQuery("#Field17").change(function(){
	if(jQuery("#ep_left_form").is("visible")==false){
	 jQuery("#ep_left_form").fadeIn("fast",function(){
	 jQuery(".page-item-21 a").trigger("click");
	 });
	 
	}
	var targeturl=jQuery(this).val();
	if(targeturl){
		jQuery.ajax({
			url: targeturl,
			success: function(data) {
			
				jQuery("#ep_right").fadeOut('fast',function(){jQuery("#ep_right").html(data).fadeIn('fast');});
			}
		});
		}
	});	
}


function initSlider(){
	var navDuration = 150; 
	var navJumpHeight = "5px";
	var navcount=2;
	jQuery('#nav a').each(function(){
		jQuery(this).attr('rel','tab'+navcount);
		var linktext=jQuery(this).text();
		jQuery(this).attr('href','#'+navcount);
		navcount++;
	});
	jQuery('#coda-slider-home').codaSlider({});
	
	jQuery('#nav a').click(function(){

		jQuery(".error").css("visibility","hidden");
		var target=jQuery(this).attr("href");
		var parent=jQuery(this).parent();
		jQuery('#nav li').removeClass("current_page_item");
		parent.addClass("current_page_item");
		var targetbutton=jQuery(this).attr("rel");
		jQuery("."+targetbutton+" a").trigger("click"); // since crosslinks don't actually seem to work, this is a little 'hack' to trigger the slider
		doNavi();
	});
	jQuery("#logo a").attr("href","#1");
	jQuery("#logo a").click(function(){
			jQuery(".tab1 a").trigger("click");
			jQuery(".error").css("visibility","hidden");
			jQuery('#nav li').removeClass("current_page_item");
			doNavi();
	});
	jQuery("#homebody").css("overflow","auto").css("height","auto").css("display","none").css("visibility","visible").fadeIn();
	//setTimeout('doNavi',500);
}

function animateNav(){
		// animate the navigation, need to add the starburst overlays
	jQuery('#nav li').hover(function() {
	jQuery(this).animate({ paddingTop : "-="+navJumpHeight }, navDuration);            
	}, function() {
	jQuery(this).animate({ paddingTop : "20px" }, navDuration);
	});
}
function initHome(){
	$.ajax({ url: "/all-site-content/", success: function(data){
	$('#homebody').html(data);
	$("#homeloading").fadeOut('normal',function(){
		$("#homebody").fadeIn('normal',function(){
			initSlider();
			initPromos();
			initMenu();
			});});
  }});
}


/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

jQuery.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};





$.tools.tooltip.addEffect("moveStarburst",
	// show function
	function(done) {
		var topoffset=14;
		var leftoffset=16;
		var conf = this.getConf(), tip = this.getTip();
		
		 
		//$(".current_page_item a").data("tooltip").show();
		
		var currenttop=$(tip).css("top");
		currenttop = parseInt(currenttop.replace("px",''));
		var newtop=(currenttop+topoffset)+"px";
		var currentleft=$(tip).css("left");
		currentleft = parseInt(currentleft.replace("px",''));
		var newleft = (currentleft+leftoffset)+"px";
		tip.css({top: newtop,left:newleft});
		//this.show();
		this.getTip().fadeIn("fast");
		done.call();
	},

	// hide function
	function(done) {
		var tip = this.getTip();
		var thetrigger=this.getTrigger();
		if($(thetrigger).parent().hasClass("current_page_item")!=true){
		 this.getTip().fadeOut("fast");
		}

		// this.getTip().fadeOut("fast");
	}
);

function doNavi(){
	var selecteditemtext=$('#nav .current_page_item a').text();
	//$('body').append(selecteditemtext);
	//$(".tooltip").hide();
	$(".tooltip").each(function(){
		if($(this).text()==selecteditemtext){
		//	$(this).data('tooltip').show();
			//$(this).fadeIn('fast');
		}
		else{
  		 $(this).hide();
  		}
	});//	$('#nav .current_page_item a').trigger('mouseout');
//$(".tooltip").hide();
}

function hideUnselectedNavItems(){
 
}


// adds an effect called "wall" to the validator
$.tools.validator.addEffect("wall", function(errors, event) {

	// get the message wall
	var wall = $(this.getConf().container).fadeIn();
	
	// remove all existing messages
	wall.find("p").remove();
	
	// add new ones
	$.each(errors, function(index, error) {
		wall.append(
			"<p><strong>" +error.input.attr("rel")+ "</strong> - " +error.messages[0]+ "</p>"
		);		
	});
	
// the effect does nothing when all inputs are valid	
}, function(inputs)  {
	
});
