// this function clears out the global text box txtEFoodie if it is Your Email address

	function  clearValue(textbox)
 	{
 	    if ($('#txtEFoodie').val()=="Your email address")
 	    {
            $('#txtEFoodie').val("");
 	    }
	}
 
 // this function is to determine the search type and change the class according ly
	function SearchType(anchor)
	{
		$('#SearchTypes li a').removeClass('Search').removeClass('Search_active').addClass('Search');
		$(anchor).removeClass('Search').addClass('Search_active');

		return false;		
	}
 // this function is to determine the search type and change the class according ly
	function SearchSite()
	{
		var activeClass = $('#SearchTypes li a.Search_active span').text();
		var textValue = $('#txtboxSearch').val();
		//var textValue = 'chicken';
		
		if(activeClass == 'Recipes')
		{
			window.location = '/Recipes/RecipeList.aspx?term=' + textValue;
		}
		else if(activeClass == 'Website')
		{
			window.location = '/Special/Search.aspx?searchmode=ExactPhrase&searchscope=SearchAllContent&searchtext=' + textValue;
			}
		else if(activeClass == 'Blog')
		{
			window.location = 'http://moreplease.centralmarket.com/search/?q=' + textValue;
		}
		return false;	
	}
	
	function searchKeypressCheck(e)
    {
        if(e.keyCode == 13)
	    {
		    SearchSite();
		    return false;
	    }
    }
    
//    function efoodieKeypressCheck(e)
//    {
//        if(e.keyCode == 13)
//	    {
//		    window.location = '/Foodie-Central/eFoodie/efoodie-sign-up.aspx' + ;
//		    return false;
//	    }
//    }
	
$(document).ready(function(){
	$('#eFoodieNewsLetter').load('/Foodie-Central/Central_Market_eFoodie.aspx', function(){bottom_logo();});
	
    $(document).pngFix();
    
    // this is the function that controls what happens when you press the enter key
    // for the home page search box
    $('input#txtboxSearch').bind('keypress', 'event', searchKeypressCheck);
    //$('input#txtEFoodie').bind('keypress', 'event', efoodieKeypressCheck);
    
    // this function is for the navigation switch
    var origImg;
    $('#MainNav li a img').hover(
        function(){
            origImg = $(this).attr('src');
            var newImg = origImg.replace('.gif', '_on.gif');
            
            $(this).attr('src', newImg);
        }, 
        function(){
            $(this).attr('src', origImg);
        }
    )
	
			

	    
    // Function used to make sure that the bottom logo stays on the bottom right
    $('#bottomLogo').css({top: $(document).height() - 161, left: $(document).width() - 194, display: 'block'});    
    $(window).resize(function(){
        var docHeight = $(document).height();
        var docWidth = $(document).width();
        var winHeight = $(window).height();
        var winWidth = $(window).width();
        
        if(winHeight > docHeight)
        {        
            $('#bottomLogo').css({top: winHeight - 161});
        }
        else
        {
            $('#bottomLogo').css({top: docHeight - 161});
        }
        
        if(winWidth > 950)
        {
            $('#bottomLogo').css({left: winWidth - 194});
        }
        else
        {        
            $('#bottomLogo').css({left: 950 - 194});
        }  

    });
    
    // This function is for the random image rotation on the stores landing page
    var storePics = new Array
    (
        '/App_Themes/CentralMarket/images/Stores/i_sm_austin_cen.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_austin_wg.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_dallas.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_ftworth.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_houston.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_plano.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_sanantonio.png',
        '/App_Themes/CentralMarket/images/Stores/i_sm_southlake.png'        
    );
	var storeAlt = new Array
    (
        'Austin-North Lamar store photo',
        'Austin-Westgate store photo',
        'Dallas store photo',
        'Forth Worth store photo',
        'Houston store photo',
        'Plano store photo',
        'San Antonio store photo',
        'Southlake store photo'        
    );
	var randNum = Math.floor(Math.random()*7);
    $('#storesImage').attr('src', storePics[randNum]).attr('alt', storeAlt[randNum]).attr('title', storeAlt[randNum]);
    
    // This is to take the border top off of the higlighted nav item
    // only if it is in first spot &    
    // stop first child of nav border top in ie6
    $('.snavsubCMSListMenuUL li:first-child, .snavsubCMSListMenuUL li:first-child span').css({border: 'none'});
    
    // this function figures out what page you are on by looking at the top of the left navigation
    // and setting the respective top nav item to a lighter green background
    // NOTES:   It uses all lower case letters in the comparison
    var pageName = $('.snavCMSListMenuLinkHighlighted').text().toLowerCase();
    
    if(pageName == 'company') { $('#MainNav li:eq(0) a img').addClass('ltGreenBg'); }
    else if(pageName == 'stores') { $('#MainNav li:eq(1) a img').addClass('ltGreenBg'); }
    else if(pageName == 'goods') { $('#MainNav li:eq(2) a img').addClass('ltGreenBg'); }
    else if(pageName == 'services') { $('#MainNav li:eq(3) a img').addClass('ltGreenBg'); }
    else if(pageName == 'recipes') { $('#MainNav li:eq(4) a img').addClass('ltGreenBg'); }
    else if(pageName == 'cooking school') { $('#MainNav li:eq(5) a img').addClass('ltGreenBg'); }
    else if(pageName == 'foodie central') { $('#MainNav li:eq(6) a img').addClass('ltGreenBg'); }
    

    // this function creates the stripes for the search results page
	$('.SearchResult:odd').addClass('Odd');
	$('.SearchResult:even').addClass('Even');
	
	// this fixes the width of the search box on the search page
	$('.CMSSearchDialogSearchForTextBox').css('width', 99);
	
	
	//Top nav item in the fookin school section
	$('.regCookSchool, .inStoreNav, .inStoreNavActive').css({borderBottom: 'solid 2px #ebd6b4'});
	
	//Drop downs for the cooking schools page
	$('#centerSubmitButton').bind("click", function(){
		//var r = $('#centerStoreDropdown').find('option').filter(':selected').text();
		
		var r = document.getElementById("centerStoreDropdown").selectedIndex;
		//var u = document.getElementsByTagName("option")[r].value;
		var u = $('#centerStoreDropdown option')[r].value;
		
		if(u == "")
		{
			alert('Please choose a local store.');
		}
		else
		{
			window.open(u);
		}
		
		return false;
	});
	
	$('#rightSubmitButton').bind("click", function(){
		//var r = $('#centerStoreDropdown').find('option').filter(':selected').text();
		
		var r = document.getElementById("rightStoreDropdown").selectedIndex;
		//var u = document.getElementsByTagName("option")[r].value;
		var u = $('#rightStoreDropdown option')[r].value;
		
		if(u == "")
		{
			alert('Please choose a local store.');
		}
		else
		{
			window.open(u);
		}
		
		return false;
	});
	
})

function bottom_logo() {
// Function used to make sure that the bottom logo stays on the bottom right
    $('#bottomLogo').css({top: $(document).height() - 161, left: $(document).width() - 194, display: 'block'});    
    $(window).resize(function(){
        var docHeight = $(document).height();
        var docWidth = $(document).width();
        var winHeight = $(window).height();
        var winWidth = $(window).width();
        
        if(winHeight > docHeight)
        {        
            $('#bottomLogo').css({top: winHeight - 161});
        }
        else
        {
            $('#bottomLogo').css({top: docHeight - 161});
        }
        
        if(winWidth > 950)
        {
            $('#bottomLogo').css({left: winWidth - 194});
        }
        else
        {        
            $('#bottomLogo').css({left: 950 - 194});
        }  

    });}


