// COMING SOON

// PAGE LOAD 

$(document).ready(function()
	{
  	   
  	   // note: see royal_common.js for the search functions
  	   
	    $("#newsletter_btn").click(function()
	    {
           newsleterClickHander();
        })
        
       
        
         shortcut.add("enter",function() {
	                   
	                   var myfocussedElement = $("*:focus").attr("id");
	                   
	                  
	                   
	                   if ( myfocussedElement == "email_txt" ) 
	                   {
	                       $("#newsletter_btn").click();
	                   }
	                   
                    });
            
        
        $("#email_txt").focus(function()
	    {
             if ( document.getElementById("email_txt").value == "Enter your email" || document.getElementById("email_txt").value == "Thank you, email received.")
             {
                 document.getElementById("email_txt").value = "";
             }
             
             $("#email_txt").css({"font-size":"11px", "font-family": "Helvetica,Arial, sans-serif", "color": "#666", "border":"2px solid #eee", "border-left": "2px solid #999",  "border-top": "2px solid #999", "width": "150px"});
        })
        
        // make space for 4 rows
        
       // var nowPlayingHeight = $("#comingsoon_onComingSoonPage").height();
        var numFilmBlocks =  4//$("#coming_soon_films_ul").length;
        var filmBlockHeight = 225;
        
        var newHeightComingSoon = (numFilmBlocks * filmBlockHeight) + 25;
        
         $("#comingsoon_onComingSoonPage").height(newHeightComingSoon);
              
         updateUIHeight(newHeightComingSoon);
        
	}
);

// 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.
*/ 

var email = "";

function newsleterClickHander()
{
    var emailStr = document.getElementById("email_txt").value;
    var emailValid = validate_email( emailStr )
       
    if ( emailValid ) 
    {
        newsletterJSONRequest();
    }
    
}

function validate_email(emailStr)
{
    var validEmail = false;
    
      var apos = emailStr.indexOf("@");
      var dotpos = emailStr.lastIndexOf(".");
      if (apos<1||dotpos-apos<2)
      {
        $("#email_txt").css({"font-size":"11px", "font-family": "Arial, Helvetica, sans-serif", "color": "Red", "border":"2px solid #eee", "border-left": "2px solid #999",  "border-top": "2px solid #999", "width": "150px"});
        validEmail = false;
      }
      else 
      {
        $("#email_txt").css({"font-size":"11px", "font-family": "Arial, Helvetica, sans-serif", "color": "#000", "border":"2px solid #eee", "border-left": "2px solid #999",  "border-top": "2px solid #999", "width": "150px"});
        validEmail = true;
        
        email = emailStr;
      }
      
      return validEmail;
}

function newsletterJSONRequest()
{
    var jsonURL = "http://roydev.audt.ca/subscribe/?email=" + email;
    $.getJSON(jsonURL, 
        function(data, textStatus){
            document.getElementById("email_txt").value =  data.message;
        });
}

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