// COMMON JS FUNCTIONS USED THROUGHOUT THE SITE

// PAGE LOAD 


$(document).ready(function()
	{
         $("#search_results").click(function()
	    {
	       var searchTermStr = document.getElementById("searchterm").value;
	       performSearch(searchTermStr);
        });
        
          $("#searchterm input").bind('keypress', function(e) {
            if(e.keyCode==13){
                 var searchTermStr = document.getElementById("searchterm").value;
                 
                 alert("enter clicked on search!");
                 
                 performSearch(searchTermStr);
            }
        });
               
      shortcut.add("enter",function() {
	                   
	                   var myfocussedElement = $("*:focus").attr("id");
	                   
	                  // alert($("*:focus").attr("id"));
	                   
	                   if ( myfocussedElement == "searchterm" ) 
	                   {
	                     var searchTermStr = document.getElementById("searchterm").value;
	                     performSearch(searchTermStr);
	                   }
	                   
                    });
        
	}
);

// NEWSLETTER
/*
You can supply an address like this:

http://roydev.audt.ca/subscribe/?email=jrudy@theatred.com

Unless you supply an email field in the query string, it raises a 404 error. 
Otherwise, it will return a json object with 2 fields: success and message. 
If the email format is valid and it’s not already in the database, it get’s added 
to the newsletter list and success equals true. If the email is not added to the 
database (because it was already there or if it’s not formatted properly), success equals false. 
message is human readable message for the user.
*/ 

function performSearch(searchTermStr, searchType)
{
    var searchTermArray = searchTermStr.split(" ").join("+");
    var plusSearchStr = String(searchTermArray);
    
    document.location.href = "http://theroyal.to/search/?q=" + plusSearchStr + "&models=theatre_events.film";
}

function updateUIHeight(mainContentHeight)
{
            var bufferHeight = 100;
                  
           
           // SLICE
           
            var sliceNewTop = mainContentHeight;
            $('.main_slice_bg').css( { "top" :  String(mainContentHeight) + "px" } );
           
            // SLICE BENEATH
                
            var sliceBoxNewTop = sliceNewTop +  $('.main_slice_bg').height() - 20;
            $('.main_whitebox_beneathslice').css( { "top" :  String(sliceBoxNewTop) + "px" } );
           
           
           // COMING SOON
           $('#comingsoon').css( { "top" :  String( sliceNewTop + 75 ) + "px" } );  
                             
           // FOOTER
           var newFooterTop = sliceBoxNewTop + $('.main_whitebox_beneathslice').height() - 2;
           $('#footer').css( { "top" :  String(newFooterTop) + "px" } );
           
           // SIDEBAR
            var sidebarNewHeight = mainContentHeight + $('.main_slice_bg').height() +  $('.main_whitebox_beneathslice').height() -  $('.sidebar_top').height() - 12;
           $('.sidebar_block').height(sidebarNewHeight);
           
           // MAIN INNNER
           var mainInnerNewHeight = mainContentHeight + mainInnerHeightDiff;
           
           $('#main_inner').height(String(mainInnerNewHeight) + "px");
           
           // MAIN HEIGHT
           
            var mainNewHeight = mainInnerNewHeight;
           
           $('#main').height(mainNewHeight);
}

