
// submit search
function submitSearch(){
   window.location.href='/search/default.aspx?searchString=' + $('#txtSearch').val() + '&src=homepage_search';
}

//check for enter key for search
function checkEnter(e){    
    // look for window.event in case event isn't passed in
    if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox 
          
    if (key == 13)
    {
        //document.getElementById('imgBtnSearch').click();
        submitSearch();
        return false;
    }else{
        return true;
    }
    
}

function showCafeMap() {
     var url = "/locations/cafes3/remote.html?src=homepage_mapbutton";
     var windWidth;
     var windHeight;
     windWidth = (window.screen.width/2) - (320 + 5);
     windHeight = (window.screen.height/2) - (200 + 25);
     poster=window.open(url,"map","scrollbars=no,resizable=no,menubar=no,status=no,toolbar=no,location=no,directories=no,width=640,height=429, left="+ windWidth + ",top=" + windHeight + ",screenX=" + windWidth + ",screenY=" + windHeight +" ");
}

function showNewsPopup(id){
    window.open('/newsdetails.aspx?id=' + id + "&src=homepage_newsstory",'ViewNews','scrollbars=no,menubar=yes,status=no,width=495,height=515');
    return false;
}

function TextSignup(el){    
   if(el.value == "Enter your email address"){
        el.value = "";
   }else if(el.value == ""){
        el.value = "Enter your email address";
   }
}

//dom ready functions
$(function(){
    
    $("#newsContainer .RSSItemLink a").each(function(){
        $(this).click(function(){
            var strTitle = $(this).find(".RSSItemTitle").html();
            
            strTitle = escape(strTitle);
                        
            showNewsPopup(strTitle);
            //showNewsPopup($(this).parent().parent().attr('id'));
            return false;
        });
    });
    
    $("#eventsContainer .RSSItemLink a").each(function(){
        $(this).click(function(){            
            
            window.open($(this).attr("href").replace("/locations/cafes3/events.aspx","/live2/eventDetails.aspx") + "&src=homepage_events",'ViewEvent','menubar=yes,width=420,height=500,scrollbars=yes');
            return false;
        });
    });
    
    
   
     
     //ie 6 & 7 fix
     var featureOffsetBottom = 0;    
      if($.browser.msie && (jQuery.browser.version.substr(0,1) < 8) ){        
         featureOffsetBottom = 2;         
      }
      
  
      
    
    //aligns all the nav dropdowns
    $("li.navItem ul:not(#lastSubMenu, #firstSubMenu)").each(function() {$(this).css("left",((($(this).width() - ($(this).parent().width() + 20) ) /2) * -1) + "px") });
    //$("li.navItem ul:last").css("left","inherit").css("right","-23px");
    
    //initialize scrollers
    $('.scrollpane').jScrollPane({scrollbarWidth: 11, showArrows:true, dragMinHeight: 39, dragMaxHeight:39});

    
    //Add mouseover to all images with "hover" as classname  
    $("img.hover, input.hover").hover(function() { 
        var imgOver = $(this).attr('src').replace(".","_over.");
        $(this).attr('src',imgOver);
    }, function() {
        var imgCurrent =  $(this).attr('src').replace("_over.", ".");
        $(this).attr('src',imgCurrent);                
    }); 
    
    //Preload all hover images
    $("img.hover,input.hover").each(function(){
        jQuery("<img>").attr("src", $(this).attr('src').replace(".","_over."));                
    }); 

    //add key listener for enter on search box       
    //$('#txtSearch').keyup(function(e) { 
    //  if(e.keyCode == 13) {   
    //    //enter key was pressed
    //    submitSearch();
    //    return false;   
    //  }   
    //});  
    
    //add key listener for search button 
    //$('#lnkSearch').click(function(){
    //   submitSearch();  
    //});
    
   
               
    //add hovers to feature boxes
    $(".featureBox").each(function(){
        $(this).click(function(){
            window.location = $(this).find("a.featureLink").attr('href');
        });
                        
        
        //Set feature text positions
        $(this).find(".featureBoxText").each(function(){                        
            $(this).animate({marginLeft: "0px"}, 1000).animate({                             
                bottom: ($(this).parent().find(".featureTitle").height() + 6 + featureOffsetBottom) + "px",
                height: ($(this).parent().find(".featureTitle").height() -4) + "px"
            });
        });
        
        
        //Set feature box text hover animations
        $(this).hover(function(){
            //hover over
            $(this).find(".featureBoxText").each(function(){
                                
                $(this).stop().animate({ 
                    //bottom: "102px",
                    //height: "92px"
                    bottom: ($(this).parent().find(".featureDesc").height() + 50 + featureOffsetBottom) + "px",
                    height: ($(this).parent().find(".featureDesc").height() + 40) + "px"
                    
                },{ duration: "slow", queue:false, complete: function(){}});                        
            });
            
            $(this).find(".featureCorner").animate({"opacity": "hide"});
            
            },function(){
            //hover out                    
                $(this).find(".featureBoxText").each(function(){                        
                    $(this).animate({marginLeft: "0px"}, 1000).animate({ 
                        //bottom: "38px",
                        //height: "28px"
                        bottom: ($(this).parent().find(".featureTitle").height() + 6 + featureOffsetBottom) + "px",
                        height: ($(this).parent().find(".featureTitle").height() -4) + "px"
                    });
                });
                $(this).find(".featureCorner").animate({marginLeft: "0px"}, {duration: 1200, queue:false}).animate({"opacity": "show"});
            }
        );
    });
    
});            
