Cufon.set('fontFamily', 'TisaPro-Light');
Cufon.replace('#home-heading');
Cufon.replace('#Portal-home-heading');
Cufon.replace('#Portal-home-subheading');
Cufon.replace('.portal-heading');
Cufon.replace('#page-title');
Cufon.replace('.c_title');
Cufon.replace('#tier2-page-title');
Cufon.replace('#manage-page-title');
Cufon.set('fontFamily', 'TisaPro-LightIta');
Cufon.replace('#home-heading span');



$(document).ready(
    function () {

        homeBackgroundImageActions();
        backgroundImageActions();

        $(".change-link").click(function () {
            $(".togglepanel").toggle();
        });

        $(".change-link1").click(function () {
            $(".togglepanel1").toggle();
        });

        $('.reset').click(function () {
            changehomeimage = 0;
            $.setCookie('homeimage', changehomeimage, {
                expires: 1
            });
        });

        $('#dnn_homenews_newsLink').click(function () {
            $.setCookie('toggle', "first", {
                expires: 1
            });
        });

        $('#dnn_pelionHeader_HyperLink1').click(function () {
            $.setCookie('toggle', "first", {
                expires: 1
            });
        });

        $('#page-canvas').append('<img src="portals/_default/skins/Pelion/public/images/Pelion_clouds.jpg" class="fullscreen-background" alt="" />').find('img.fullscreen-background').load(function () {
            centerBackgroundImage($(this));
        });

        $('#page-canvas-admin').append('<img src="../portals/_default/skins/Pelion/public/images/Pelion_clouds.jpg" class="fullscreen-background" alt="" />').find('img.fullscreen-background').load(function () {
            centerBackgroundImage($(this));
        });

        $("#tabs").tabs({
            fx: { opacity: 'toggle' },
            spinner: '<h2>Retrieving data...</h2>',
            speed: 'slow'
        });

        //hide the all of the element with class msg_body
      //  $(".msg_body").hide();
      //  if ($.cookie('toggle') == "first") {
      //      $(".msg_body:first").slideDown(600);
       //     $(this).find(".toggle-image:first").attr("src", "portals/_default/Skins/Pelion/public/images/tier2/close_arrow.png");
      //  }



    });




function backgroundImageActions() {
    $('#page-canvas').css("height", $(window).height())
    setupBodyHeight();
}

function centerBackgroundImage(target) {
    target = $(target);
    var the_window = $(window);

    target.css({
        'width': 'auto',
        'height': the_window.height()
    });

    // if the window width is wider than the resized image we need to set the image width to the window width

    if (target.attr("width") < the_window.width()) {
        target.css({
            'width': the_window.width(),
            'height': 'auto'
        });
    }

    var margin_top = (the_window.height() / 2) - (target.height() / 2);
    var margin_left = Math.floor(the_window.width() / 2 - (target.width() / 2));

    $(target).css({
        'margin-left': margin_left + 'px'
    });
}

function setupBodyHeight() {
    body = $('body');

    body.height('auto');

    if ($('#page-canvas').height() < body.height()) {
        body.height('100%');
    }
    else if ($('#page-canvas').height() != body.height()) {
        body.height('auto');
    }
}

$(window).resize(function () {
    centerBackgroundImage($('#page-canvas img.fullscreen-background'));
    backgroundImageActions();
});

//homepage
function homeBackgroundImageActions() {
    $('#home-page-canvas').css("height", $(window).height())
    setupBodyHeight();
}

function homeCenterBackgroundImage(target) {
    target = $(target);
    var the_window = $(window);

    target.css({
        'width': 'auto',
        'height': the_window.height()
    });

    // if the window width is wider than the resized image we need to set the image width to the window width

    if (target.attr("width") < the_window.width()) {
        target.css({
            'width': the_window.width(),
            'height': 'auto'
        });
    }

    var margin_top = (the_window.height() / 2) - (target.height() / 2);
    var margin_left = Math.floor(the_window.width() / 2 - (target.width() / 2));

    $(target).css({
        'margin-left': margin_left + 'px'
    });
}

function homeSetupBodyHeight() {
    body = $('body');

    body.height('auto');

    if ($('#home-page-canvas').height() < body.height()) {
        body.height('100%');
    }
    else if ($('#home-page-canvas').height() != body.height()) {
        body.height('auto');
    }
}

$(window).resize(function () {
    homeCenterBackgroundImage($('#home-page-canvas img.fullscreen-background'));
    homeBackgroundImageActions();
});


