﻿Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h4');
Cufon.replace('#left-nav a span');
Cufon.replace('#search div.form-label');
Cufon.replace('a.arrow-link', { hover: true });
Cufon.replace('#top-nav ul li a', { hover: true });
Cufon.replace('#header-nav ul li a', { hover: true });
Cufon.replace('.h1-lowercase');
Cufon.replace('a.button span span');

Cufon.replace('div.event-time');

$(document).ready(function () {

    /* HACK to fix accommodation image temporarily */
    if ($("#ctl00_MainContent_pnlRooms").length > 0) {
        $("div.pub-image img").removeClass("right-image");
    }


    /* Fix the minimum height of the content relative to the left col */
	
	if ($('table.photo-gallery').length ==0) {
		if ($("#content-inner").height() < $("#left-col").height()) {
			$("#content-inner").height($("#left-col").height());
		}
 	}
    /* Print button interaction */
    $(".print").click(function () {
        if ($(".pub-description").length > 0 && $("#pub-description-print").length < 1) {
            $(".pub-description").clone().attr("id", "pub-description-print").addClass("hidden").insertAfter("#right-col");
        }
        window.print();
        return false;
    });

    /* slide toggle interactions */
    $(".closed").hide();

    $(".toggle").click(function () {
        var target = $(this).attr("rel");
        var newText = $(this).attr("title");
        var oldText = $(this).text();
        $(target).toggle("slow");
        $(this).attr("title", oldText).text(newText);
        return false;
    });

    $('.inline-box[rel]').overlay({
        close: '.close',
        fixed: false,
        top: '2%',
        mask: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.5
        }
    });
    $('#btnCancelEmail').click(function () { return false; });

    $(".send-box[rel], .apply-box[rel], #apply-trigger, #send-trigger")
        .click(function () {
            $("div.message-error, div.message-success").hide();
            if ($(this).hasClass('apply-box')) {
                var arrInfo = $(this).attr('title');
                arrInfo = arrInfo.split("|");
                $("#ctl00_OverlayContent_txtRecipientEmail").val(arrInfo[0]);
                $("#ctl00_OverlayContent_txtSubject").val(arrInfo[1] + ', ' + arrInfo[2] + ', ' + arrInfo[3]);
                $("#jobName").text(arrInfo[1]);

                $("#btnCancelApplication").click(function () { return false; });
            }
            if ($(this).hasClass('send-box')) {
                var arrInfo = $(this).attr('title');
                arrInfo = arrInfo.split("|");
                $("#ctl00_OverlayContent_txtJobLocation").val(arrInfo[2] + ', ' + arrInfo[3]);
                $("#ctl00_OverlayContent_txtJobName").val(arrInfo[1]);
                $("#jobName2").text(arrInfo[1]);

                $("#btnCancelShare").click(function () { return false; });
            }
        })
        .overlay({
            close: '.close',
            fixed: false,
            top: '2%',
            mask: {
                color: '#000',
                loadSpeed: 200,
                opacity: 0.5
            }
        });


    $("a[rel=pub-gallery-1], a[rel=accommodation-gallery]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });

    SimplyButtons.init();



});

/* CV UPLOADIFY */
// Limit: 20mb, JPEG format only.
function initCvUploadify() {

    if ($("#ctl00_OverlayContent_cvAttachment").val() != '') {
        var val = $("#ctl00_OverlayContent_cvAttachment").val();
        var arrVal = val.split("/");
        var fileName = arrVal[arrVal.length-1];
        $("#attachment-name").html(fileName);
        $("#uploadPanel").hide();
    } else {
        $("#attachmentPanel").hide();
    }

    $('#btnUploadCv').uploadify({
        scriptData: {},
        wmode: 'opaque',
        uploader: '/swf/uploadify.swf',
        script: '/upload.ashx',
        cancelImg: '/gfx/icon-cancel.png',
        auto: true,
        multi: false,
        folder: '/uploads/temp/cv',
        fileExt: '*.doc;*.docx;*.pdf',
        fileDesc: 'Word or PDF file',
        sizeLimit: 20480000,
        onComplete: function (event, queueID, fileObj, response, data) {
            $("#attachment-name").html(fileObj.name);
            $("#ctl00_OverlayContent_cvAttachment").val(response);
            displayAttachment();
        }
    });

    $("#cancelAttachment").click(function() { clearAttachment(); return false; });
}

function displayAttachment(strName) {
    $("#attachmentName").text(strName);
    $("#uploadPanel").hide();
    $("#attachmentPanel").show();
}

function clearAttachment() {
    $("#attachmentPanel").hide();
    $("#attachmentName").text('');
    $("#cvAttachment").val('');
    $("#uploadPanel").show();
}
