$(window).resize(function() {
    var offset = $('#footer').offset();
    footerDif=$(window).height()-(offset.top+182);
    if(footerDif>0) {
        $('#footerFiller').css('height',footerDif-10+'px');
    }
});
$(document).ready(function () {
    var offset = $('#footer').offset();
    footerDif=$(window).height()-(offset.top+182);
    if(footerDif>0) {
        $('#footerFiller').css('height',footerDif-10+'px');
    }
    $('.searchError').children('a').click(function() {
        $('.searchError').fadeOut(300,function() {
            $('.searchError').hide(0)
        })
    });
    $(document).keyup(function(e) {
        if (e.keyCode == 27) {
            $('.searchError').fadeOut(300,function() {
                $('.searchError').hide(0)
            });
        }   // esc
    });
		
    $(".searchBox").focus(function () {
        $(this).val('');
    });
});
//this method is for the search for movie box
function search(){
    //get the user entered value
    var name = $('#searchBox').val().replace(/\//g," ");
    //chekc on the constrain
    if(name.length >= 3){
        //success value prepare the request url
        name = '/' + encodeURIComponent(name);
        //go to the search page
        window.location = searchUrl + name;
    } else {
        //the constrain fails display the error message
        $('.searchError').css('display','block');
        $('.searchError').css('right','-28px');
        $('.searchError').css('top','7px');
    }
}

function logout(){
    $.ajax({
        type: 'POST',
        url: prelogoutURL,
        success: function(){
            window.location.href=logoutURL;
        }
    });
}
//this function is responsible for changing the notification number
function changeMessagsNotification(){
    //requst the new messages count
    $.ajax({
        type: 'GET',
        url: messageCountUrl,
        success: function(msg) {
            //check if session expired
            if(msg == "login"){
                //redirect the user to login
                window.location = loginUrl;
            } else {
                //get the new notification count
                newMessagesCount = parseInt(msg);
                if(newMessagesCount > 0){
                    $('#messageIcon').html('<div class="notNumber">'+newMessagesCount+'</div>');
                    $('#messageIcon').removeClass();
                    $('#messageIcon').addClass('messages');
                } else {
                    $('#messageIcon').html('');
                    $('#messageIcon').removeClass();
                    $('#messageIcon').addClass('messagesS');
                }
            }
            //add the new messages count to the drop down list
            $('#notificationSpan').html('('+newMessagesCount+' unread)');
        }
    });
}
//this function is responsible for changing the notification number
function notificationsNumber(){
    $.ajax({
        type: 'GET',
        url: notificationNumberUrl,
        success: function(msg) {
            //check if session expired
            if(msg == "login"){
                //redirect the user to login
                window.location = loginUrl;
            } else {
                //get the new notification count
                newNotificationsCount = parseInt(msg);
                if(newNotificationsCount > 0){
                    //set the new count
                    $('#noteIcon').html('<div class="notNumber">'+newNotificationsCount+'</div>');
                    $('#noteIcon').removeClass();
                    $('#noteIcon').addClass('nots');
                    
                } else {
                    $('#noteIcon').html('');
                    $('#noteIcon').removeClass();
                    $('#noteIcon').addClass('notsS');
                }
            }
        }
    });
}

//this function is responsible for check if there is logged in facebook user
function facebookAutoLogging(){
//    alert(window.location);
    data = 'url='+window.location;
    $.ajax({
        type: 'GET',
        url: facebookAutomaticLogin,
        data: data,
        success: function(url) {
            if(url != "noFacebook"){
                //redirect the user to login
                window.location = url;
            } 
        }
    });
}

