/*
*	Bonefish Grill
*	Contains utility / interface functions for Bonefish Grill
*	
*	Requires jQuery library (http://www.jquery.com),
*	SWFObject (http://blog.deconcept.com/swfobject/),
*	sIFR (http://www.mikeindustries.com/sifr/)
*	
*	Taylan Pince (taylan@trapeze.com) - January 30, 2007
*/

if (typeof trapeze == 'undefined') trapeze = new Object();

trapeze.boneFish = {
	
	mark_js : function() {
		$("html").addClass("has-js");
	},
	
	mark_lists : function() {
		$("li:last-child").addClass("last-child");
		$("li:first-child").addClass("first-child");
	},
	
	mark_forms : function() {
		$("input[@type=text]").addClass("text");
		$("input[@type=password]").addClass("text");
		$("input[@type=file]").addClass("file");
		$("input[@type=radio]").addClass("radio");
		$("input[@type=checkbox]").addClass("checkbox");
		$("input[@type=image]").addClass("image");
	},
	
	mark_separators : function() {
		$("hr").wrap('<div class="hr"></div>');
	},
	
	mark_iepng : function() {
		if ($.browser.msie && parseInt($.browser.version) < 7) {
			$("#HomeFeatures li img, #VideoPlayer img").each(function() {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + this.src + "')";
				this.src = trapeze.boneFish.media_path + "images/blank.png";
			});
		}
	},
	
	init_sifr : function() {
		if (typeof sIFR == "function") {
			sIFR.replaceElement(named({sSelector:"#MenuNavigationHeader", sFlashSrc:this.media_path + "flash/crandall-bold.swf", sColor:"#231f20", sLinkColor:"#231f20", sBgColor:"#FFFFFF", sHoverColor:"#620601", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
		};
	},
	
	init_home_sifr : function() {
		if (typeof sIFR == "function" && $("body").attr("class").indexOf("home") > -1) {
			sIFR.replaceElement(named({sSelector:"#HomeContent h1, #HomeFeatureBottom h3", sFlashSrc:this.media_path + "flash/crandall-bold.swf", sColor:"#353d5a", sLinkColor:"#353d5a", sBgColor:"#FFFFFF", sHoverColor:"#620601", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
			sIFR.replaceElement(named({sSelector:"#HomeContentLink h1, #HomeContent h2, #HomeFeatureBottom h2, #HomeFeatures h3", sFlashSrc:this.media_path + "flash/crandall-bold.swf", sColor:"#822827", sLinkColor:"#822827", sBgColor:"#FFFFFF", sHoverColor:"#620601", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
		};
	},
	
	nav_types : {
		
		"top" : {
			"container_id" : "TopNavigation",
			"flash_id" : "TopNavigationFlash",
			"flash_width" : 765,
			"flash_height" : 30,
			"flash_path" : "flash/nav.swf"
		},
		
		"menu" : {
			"container_id" : "MenuNavigation",
			"flash_id" : "MenuNavigationFlash",
			"flash_width" : 750,
			"flash_height" : 30,
			"flash_path" : "flash/menunav.swf"
		}
		
	},
	
	init_nav : function(type) {
		var nav = this.nav_types[type];
		
		if ($("#" + nav["container_id"]).size() > 0) {
			var xml = "<nav>";
			$("#" + nav["container_id"]).find("a").each(function() {
				xml += "<menu src='" + $(this).attr("href") + "'";

				var attributes = $(this).attr("class");
				if (typeof attributes != "undefined") {
					if (attributes.indexOf("active") > -1) xml += " sel='true'";
					if (attributes.indexOf("arrow") > -1) xml += " arrow='true'";
				}

				xml += ">" + $(this).text().replace("&", "%26") + "</menu>";
			});
			xml += "</nav>";
			
			$("#" + nav["container_id"]).replaceWith('<div id="' + nav["container_id"] + '"></div>');
			
			var so = new SWFObject(trapeze.boneFish.media_path + nav["flash_path"], nav["flash_id"], nav["flash_width"], nav["flash_height"], "8", "#FFFFFF");
			so.addVariable("nav", xml);
			so.addParam("wmode", "transparent");
			so.write(nav["container_id"]);
		}
	},
	
	init_player : function() {
		if ($("#VideoPlayer").size() > 0 && this.player_prefs) {
			var so = new SWFObject(this.media_path + "flash/player.swf", "VidePlayerFlash", 402, 321, "8", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("prefs_path", this.player_prefs);
			so.write("VideoPlayer");
		}
	},
	
	init_menu_download : function() {
		if ($("#DownloadMenu").size() > 0) {
			$("#DownloadMenu").change(function() {
				if ($(this).val() != "") {
					window.location = $(this).val();
				}
			});
		}
	},
	
	init : function() {
		this.mark_js();
		this.mark_lists();
		this.mark_forms();
		this.mark_separators();
		this.mark_iepng();
		this.init_nav("top");
		this.init_nav("menu");
		this.init_sifr();
		this.init_home_sifr();
		this.init_menu_download();
		this.init_player();
	}
	
};

$(function() {
	trapeze.boneFish.init();
});
