jQuery(document).ready(function() {
    $('textarea.editor').each(function() {
        CKEDITOR.replace($(this).attr('id') );
    });
    jQuery('.addPagesFrom').hide();       
    jQuery(".addPageButton").click(function(){
        jQuery('.addPagesFrom').slideDown("fast");
        jQuery('.showPages').slideUp("fast");
    });
    jQuery(".showPageButton").click(function(){
        jQuery('.addPagesFrom').slideUp("slow");
        jQuery('.showPages').slideDown("slow");
        jQuery('.pageContent').slideUp("slow");
    });
    jQuery(".pageTitle").click(function(){
        var contentDiv = '#pageContent' + this.id;
        jQuery('.pageContent').slideUp("fast");
        jQuery(contentDiv).slideDown("fast");
    });
    jQuery(".changePageContentButton").click(function(){
        var pageID = this.id;
        jQuery('.pageContent').slideUp("fast");
        jQuery('#pageContent' + pageID).slideDown("fast");
    });
    jQuery("h2").click(function(){
        if(jQuery(this).find("p").css("display") == "block"){
            jQuery(this).find("p").slideUp("fast");                
        }
        else {
            jQuery("h2").find("p").slideUp("fast");
            jQuery(this).find("p").slideDown("fast");
        }
    });
    jQuery(".icon").click(function(){
        if(jQuery(".filmRental").css("display") == "block"){
            jQuery(".filmRental").fadeOut("slow");                
        }
        else {
            jQuery(".filmRental").fadeIn("slow");
        }
    });
    jQuery(".closeFilmRental").click(function(){
        jQuery(".filmRental").fadeOut("slow");  
    });
    jQuery(".sendMaiL").click(function(){
        if(jQuery('input#name').val() == ""
            || jQuery('input#email').val() == ""
            || jQuery('textarea#message').val() == ""){
                        
            alert("All fields marked red are required.");
            jQuery('input#name').css("border","1px solid red");
            jQuery('input#email').css("border","1px solid red");
            jQuery('textarea#message').css("border","1px solid red");
        }
        else {
            jQuery('.sm').submit();
        }
    });
    $('.img').hover(function(){
        //alert(this.id);
        $('#bigImage'+this.id).show();
    }); 
    $('.img').mouseout(function(){
        $('#bigImage'+this.id).hide();
    });
    $(document).mousemove(function(e){
        var x = e.pageX - 400 + "px";
        var y = e.pageY - 120 + "px";
        $('.bigImage').css({
            top: y
        });
        $('.bigImage').css({
            left: x
        });
    }); 
        
    jQuery(".editImage").click(function(){
        var imgID = this.id;
        jQuery('#imageContentEdit' + imgID).fadeIn("fast");
    });
    
    
    
    // FUNCTION CENTER
    jQuery.fn.center = function (absolute) {
        return this.each(function () {
            var t = jQuery(this);

            t.css({
                position:    absolute ? 'absolute' : 'fixed', 
                left:        '50%', 
                top:        '50%', 
                zIndex:        '99'
            }).css({
                marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
                marginTop:    '-' + (t.outerHeight() / 2) + 'px'
            });

            if (absolute) {
                t.css({
                    marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                    marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
                });
            }
        });
    };
    //jQuery('.pimg img:first-child').center(true);
});
function confirmDeleteImageSubmit(){
    var agree=confirm("Сигурни ли сте, че искате да изтриете тази снимка?");
    if (agree)
        return true ;
    else
        return false ;
}
function confirmDeletePageSubmit(){
    var agree=confirm("Сигурни ли сте, че искате да изтриете тази страница?");
    if (agree)
        return true ;
    else
        return false ;
}
