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

bonefishGrill = {

	mark_lists : function() {
		jQuery("li:last-child").addClass("last-child");
		jQuery("li:first-child").addClass("first-child");
	},
	
	mark_forms : function() {
		jQuery("input[@type=text]").addClass("text");
		jQuery("input[@type=password]").addClass("text");
		jQuery("input[@type=file]").addClass("file");
		jQuery("input[@type=radio]").addClass("radio");
		jQuery("input[@type=checkbox]").addClass("checkbox");
		jQuery("input[@type=image]").addClass("image");
	},
	
    home_calendar : function() {
		if (jQuery("#homeCalendar").size() > 0) {
			var so = new SWFObject(this.home_calendar_swf_path, "videoPlayer", "964", "485", "9", "#FFFFFF");
			so.addParam("allowScriptAccess", "always");
			so.addParam("wmode", "transparent");
			so.addParam("scale", "noscale");
			so.addParam("salign", "T");
			so.addVariable("prefsPath", this.home_calendar_prefs_path);
			//so.addVariable("startAfterLoad", ((start_first)? "true" : "false"));
			so.write("homeCalendar");   
		};
		
    },
	locator_button : function(){
			var so = new SWFObject(this.locator_button_path, "videoPlayer", "284", "54", "9", "#FFFFFF");
			so.addParam("allowScriptAccess", "always");
			so.addParam("wmode", "transparent");
			so.addParam("scale", "noscale");
			so.addParam("salign", "T");	
			so.write("findSpecials");   
		
	},	
    responsibility_tabs : function(){
        if (jQuery('.responsibility-page').size() > 0) {
            jQuery(".video-tab").css("display","none");
            jQuery("#VideoMenu a").click(function(event){
                event.preventDefault();
                var player_path = jQuery(this).attr("class");
                bonefishGrill.responsibility_player(player_path);
                if (jQuery('.active').size() > 0) {
                    jQuery('.active').css("display","none");
                }
                target =  jQuery(this).attr("href");
                jQuery(target).css("display","inline"); 
                jQuery(target).attr("class","active");      
            });
        }
    },
    responsibility_player : function(player_path){
        if(jQuery("#OrdinaryPlayer").size() > 0 && this.small_player_prefs && this.small_player_path) {
            var myPath = this.small_player_path + player_path + ".xml";
            var so = new SWFObject(this.media_path + "flash/smaller-player.swf", "FlightPlayerFlash", 342, 280, "8", "#FFFFFF");
            so.addParam("allowScriptAccess", "always");
            so.addParam("wmode", "transparent");
            so.addVariable("prefs", this.media_path + "xml/flight_player_prefs.xml");
            so.addVariable("path", myPath);
            so.write("OrdinaryPlayer");
        }
    },
	sifr : function() {
		if (typeof sIFR == "function") {
            //headers
            sIFR.replaceElement(named({sSelector:"h1.section-title", sFlashSrc:this.media_path + "flash/fAWeSOMeB.swf", sColor:"#303030", sLinkColor:"#303030", sBgColor:"#FFFFFF", sHoverColor:"#303030", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
            sIFR.replaceElement(named({sSelector:"h2.section-title", sFlashSrc:this.media_path + "flash/fAWeSOMeB.swf", sColor:"#303030", sLinkColor:"#303030", sBgColor:"#FFFFFF", sHoverColor:"#303030", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
            sIFR.replaceElement(named({sSelector:"h3.block-title", sFlashSrc:this.media_path + "flash/fAWeSOMeB.swf", sColor:"#303030", sLinkColor:"#303030", sBgColor:"#FFFFFF", sHoverColor:"#303030", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
            sIFR.replaceElement(named({sSelector:"h4.block-link", sFlashSrc:this.media_path + "flash/fAWeSOMeB.swf", sColor:"#620500", sLinkColor:"#620500", sBgColor:"#FFFFFF", sHoverColor:"#620500", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
		};
	},

    init_navigation : function(nav_path, subnav_path) {
        if (jQuery("#MainNav").size() > 0) {
            var so = new SWFObject(this.main_nav_path, "MainNavFlash", "790", "31", "9", "#ffffff");
            so.addParam("allowScriptAccess", "always");
            so.addParam("scale", "noscale");
            so.addParam("salign", "T");
            so.addParam("wmode", "transparent");
            so.addVariable("xmlPath", nav_path);
            so.addVariable("itemSelected", ((bonefishGrill.mainNavItemSelected)?bonefishGrill.mainNavItemSelected : "-1"));
            so.write("MainNav");
        }
        

        if (jQuery("#menuNavText").size() > 0) {
            var so = new SWFObject(this.sub_nav_path, "SubNavFlash", "950", "31", "9", "#ffffff");
            so.addParam("allowScriptAccess", "always");
            so.addParam("scale", "noscale");
            so.addParam("salign", "T");
            so.addParam("wmode", "transparent");
            so.addVariable("xmlPath", subnav_path);
            so.addVariable("itemSelected", ((bonefishGrill.subNavItemSelected)?bonefishGrill.subNavItemSelected : "-1"));
            so.write("menuNavText");
        }
        
    },
    
    style_breadcrumb : function() {
        if (jQuery("div#genericTopCopy.breadcrumb").size() > 0) {
            jQuery("div#genericTopCopy.breadcrumb a:last").each(function(){
                jQuery(this).replaceWith('<span class="breadcrumbSelected">' + jQuery(this).text() + '</span>');
            });
        }
    },

    build_fish_scroller : function() {
        if (jQuery("#fishScroller").size() > 0) {
            if (jQuery("#fishScroller ul li").length > 6) {                
                //hides all items after the sixth
                jQuery("#fishScroller ul li:gt(5)").hide();
                
                //includes the scroll buttons
                jQuery("#fishScroller ul").before('<ul><li><img id="prevBtn" src="'+bonefishGrill.media_path+'img/fish_scroller_left_arrow.jpg" width="26" height="75" border="0" alt="Left" /></li></ul>')
                                     .after('<ul><li><img id="nextBtn" src="'+bonefishGrill.media_path+'img/fish_scroller_right_arrow.jpg" width="26" height="75" border="0" alt="Right" /></li></ul>');

                bonefishGrill.show_hide_scrollButtons();
                
                //changes the style of the scroller blocks
                jQuery("#fishScroller")
                    .css('height','113px')
                    .css('overflow', 'hidden')
                .find('ul:gt(0)')
                    .css('padding-left', '0px')
                .parent().find('ul#fishScrollerList')
                    .css('width', '876px')
                    .css('overflow', 'hidden')
                .parent().find('li')
                    .css('margin-right', '10px')
                .filter(':last')
                    .css('margin-right', '0px');
                
                jQuery("#prevBtn").click(function(){
                    if (bonefishGrill.firstOnScroller > 0) {
                        jQuery("#fishScrollerList li:eq("+(bonefishGrill.firstOnScroller-1)+")").animate({
                            width: "134px",
                            opacity: 100
                        }, 800).find('p')
                            .css('display', 'block');
                        
                        jQuery("#fishScrollerList li:eq("+bonefishGrill.lastOnScroller+")").animate({
                            width: "0%" ,
                            opacity: 0
                        }, 800, function(){
                            jQuery(this).css('display', 'none');
                        }).find('p').css('display', 'none');
                        
                        bonefishGrill.firstOnScroller--;
                        bonefishGrill.lastOnScroller--;
                        
                        bonefishGrill.show_hide_scrollButtons();
                    }

                });
                
                jQuery("#nextBtn").click(function(){
                    if (bonefishGrill.lastOnScroller < (jQuery("#fishScrollerList li").length - 1)) {
                        jQuery("#fishScrollerList li:eq("+bonefishGrill.firstOnScroller+")").animate({
                            width: "0%",
                            opacity: 0
                        }, 800, function(){
                            jQuery(this).css('display', 'none');
                        }).find('p').css('display', 'none');
                       
                        jQuery("#fishScrollerList li:eq("+(bonefishGrill.lastOnScroller+1)+")").animate({
                                width: "134px",
                                opacity: 100
                            }, 800).find('p')
                                .css('display', 'block');                    
    
                        bonefishGrill.firstOnScroller++;
                        bonefishGrill.lastOnScroller++;
                        
                        bonefishGrill.show_hide_scrollButtons();
                    }
                });
                
            }
        }
    },
    
    show_hide_scrollButtons : function() {
        if (bonefishGrill.firstOnScroller == 0) {
            jQuery("#fishScroller ul li:eq(0)")
                .css('cursor', 'auto')
                .find('img').animate({opacity: 0}, 0);
        } else {
            jQuery("#fishScroller ul li:eq(0)")
                .css('cursor', 'pointer')
                .find('img').animate({opacity: 100}, 100);
        }
       
        if (bonefishGrill.lastOnScroller == (jQuery("#fishScrollerList li").length - 1)) {
            jQuery("#fishScroller ul li:last")
                .css('cursor', 'auto')
                .find('img').animate({opacity: 0}, 0);
        } else {
            jQuery("#fishScroller ul li:last")
                .css('cursor', 'pointer')
                .find('img').animate({opacity: 100}, 0);
        }
    },
    
    set_pop_up : function() {
        jQuery('a[@rel="external"]').click( function() {
            window.open( jQuery(this).attr('href'), '', 'width=640,height=480,menubar=no,toolbar=no' );
            return false;
        });
    },

    dynamic_archive_links : function() {
        jQuery('ul.dispatch-archive-months').hide().parent().find('.dispatch-archive-year').prepend('<img src="'+this.media_path+'img/arrow_down.png" alt="hide months" style="display:none;" class="img-arrow-hide" /><img src="'+this.media_path+'img/arrow_right.png" alt="show months" class="img-arrow-show" />&nbsp;').css('cursor', 'pointer').click(function(){
            jQuery(this).find('+ ul.dispatch-archive-months').toggle();
            jQuery(this).find('img').toggle();
        });
    },
    
    flight_player : function() {
        if (jQuery("#flightSpecialsTopRight").size() > 0 && bonefishGrill.flight_player_prefs && bonefishGrill.flight_player_content) {
            var so = new SWFObject(this.media_path + "flash/flight_player.swf", "FlightPlayerFlash", 325, 337, "8", "#FFFFFF");
            so.addParam("allowScriptAccess", "always");
            so.addParam("wmode", "transparent");
            so.addVariable("prefs", bonefishGrill.flight_player_prefs);
            so.addVariable("path", bonefishGrill.flight_player_content);
            so.write("flightSpecialsTopRight");
        }
    },
    
    fish_region_map : function() {
		if (jQuery("#FishRegionMap").size() > 0 && jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
			jQuery("#FishRegionMap > img").each(function() {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + this.src + "')";
				this.src = bonefishGrill.media_path + "img/blank.png";
			});
			
			jQuery("#FishRegionMap").each(function() {
				var bg = this.currentStyle.backgroundImage;
				var method = (this.currentStyle.backgroundRepeat == "no-repeat") ? "crop" : "scale";
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='" + method + "', src='" + bg.substring(5, bg.length - 2) + "')";
				this.style.backgroundImage = "url('" + bonefishGrill.media_path + "img/blank.png')";
				jQuery(this).find("a").css("position", "relative");
			});
		}
    },
    
    init_locator_form : function() {
        if (jQuery("#LocatorForm").size() > 0) {
            //bonefishGrill.switch_locator_form(jQuery("#LocatorForm").find("#id_zipcity").val(), "#id_state", "bottom");
            jQuery("#LocatorForm").find("#id_zipcity").keyup(function() {
                //bonefishGrill.switch_locator_form(this.value, "#id_state", "bottom");
            });
            
            //bonefishGrill.switch_locator_form(jQuery("#LocatorForm").find("#id_state").val(), "#id_zipcity, #id_radius", "top");
            jQuery("#LocatorForm").find("#id_state").change(function() {
                //bonefishGrill.switch_locator_form(this.value, "#id_zipcity, #id_radius", "top");
            });
        }
    },
    
    switch_locator_form : function(val, ids, css) {
        if (val == "") {
            jQuery("#LocatorForm").find(ids).attr("disabled", false);
            jQuery("#LocatorForm").find("td.locator-" + css + "-label, td.locator-mid-label").removeClass("disabled");
        } else {
            jQuery("#LocatorForm").find(ids).attr("disabled", true);
            jQuery("#LocatorForm").find("td.locator-" + css + "-label, td.locator-mid-label").addClass("disabled");
        }
    },
    
    init_feed_form : function() {
        if (jQuery("#CustomFeedsForm").size() > 0) {
            jQuery("#CustomFeedsFormLocationSelector").html("");
            jQuery("#CustomFeedsFormStateSelector").css("display", "block").find("select").attr("disabled", true);
            
            jQuery("#id_CustomFeedForm-local_updates").click(function() {
                jQuery("#CustomFeedsFormStateSelector").find("select").attr("disabled", !this.checked);
                
                if (this.checked) {
                    bonefishGrill.load_feed_locations();
                } else {
                    jQuery("#CustomFeedsFormLocationSelector").html("");
                }
            });
            
            jQuery("#id_CustomFeedForm-state").change(function() {
                bonefishGrill.load_feed_locations();
            });
            
            if (jQuery("#id_CustomFeedForm-local_updates").attr("checked") == true) {
                jQuery("#id_CustomFeedForm-state").attr("disabled", false);
                
                bonefishGrill.load_feed_locations();
            }
        }
    },
    
    load_feed_locations : function() {
        if (jQuery("#id_CustomFeedForm-state").val() != "") {
            jQuery("#CustomFeedsFormLocationSelector").load(bonefishGrill.feed_locations_url.replace("00", jQuery("#id_CustomFeedForm-state").val()));
        }
    },

	menuSpecial : function(){
		document.getElementById("menuSpecial").style.display = "block";
		
		setTimeout("bonefishGrill.showMenuSpecial();",2000);
		this.menuSpecialInterval = setInterval("bonefishGrill.animateInMenuSpecial();",1);
		this.menuSpecialPos = -1000;
		this.menuSpecialTarget = -1000;
	},
	
	hideMenuSpecial : function(){
		this.menuSpecialTarget = -1000;
		setTimeout("bonefishGrill.killMenuSpecialInterval",10000);
	},
	
	killMenuSpecialInterval : function(){
		clearInterval(this.menuSpecialInterval);
	},
	
	showMenuSpecial : function(){
		this.menuSpecialTarget = 0;
		setTimeout("bonefishGrill.hideMenuSpecial();",20000);
	},
	
	animateInMenuSpecial : function(){

			this.menuSpecialPos -= (this.menuSpecialPos - this.menuSpecialTarget)*0.1;
			document.getElementById("menuSpecial").style.top = this.menuSpecialPos + "px";
		
		//alert(this.menuSpecialPos);
	},
	
    init : function() {
		
		var homepage = jQuery('.home-page').length > 0 ? true : false;
		
        this.mark_lists();
        this.mark_forms();
      //  this.sifr();
        this.init_navigation('/navigation/main-nav/', '/navigation/sub-nav/');
        this.style_breadcrumb();
        this.build_fish_scroller();
        this.set_pop_up();
        this.dynamic_archive_links();
        this.flight_player();
        this.fish_region_map();
        this.init_locator_form();
        this.init_feed_form();
        this.responsibility_tabs();
		this.home_calendar();	
		this.locator_button();
    }
}

jQuery(document).ready(function(){
    bonefishGrill.firstOnScroller = 0;
    bonefishGrill.lastOnScroller = 5;
    bonefishGrill.init();
});
