﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

var PAR = {};

PAR.History = {
    scroller: null,

    init: function() {
        this.scroller = jQuery('div.scrollable');
        if (this.scroller)
            jQuery(this.scroller).scrollable({size: 3, clickable: false}).mousewheel();
    }
};

PAR.OilFieldCycle = {
    instance: null,
    element: null,
    flag: null,
    init: function() {
        this.element = jQuery("#oil-field-cycle");
        if (this.element)
            this.setBehavior();
    },
    setBehavior: function() {
        instance = this;
        jQuery("#of-time-nav a").hover(function() {
            if (jQuery(this).hasClass("selected")) {
                jQuery(this).removeClass("selected");
                instance.flag = jQuery(this).attr('class');
            }
            else
                instance.flag = '';
            jQuery(this).addClass("selected");
        }, function() {
            jQuery(this).removeClass("selected");
            if (instance.flag == jQuery(this).attr('class'))
                jQuery(this).addClass("selected");
        });
        jQuery("#of-navigator a").hover(function() {
            elemClass = jQuery(this).attr("class");
            jQuery("#of-time-nav ." + elemClass).addClass("selected");
        }, function() {
            elemClass = jQuery(this).attr("class");
            jQuery("#of-time-nav ." + elemClass).removeClass("selected");
        });

        jQuery("#of-time-nav a").click(function(e) {
            instance.clearSelection();
            elemClass = jQuery(this).attr("class");
            instance.flag = elemClass;
            instance.setContent(elemClass);
        });
        jQuery("#of-navigator a").click(function(e) {
            instance.clearSelection();
            elemClass = jQuery(this).attr("class");
            instance.setContent(elemClass);
        });
    },
    setContent: function(elemClass) {
        jQuery("#of-time-nav ." + elemClass).addClass("selected");
        jQuery("#of-text-content ." + elemClass).addClass("display");
        jQuery("#of-navigator ." + elemClass).addClass("selected");
    },
    clearSelection: function() {
        jQuery("#of-time-nav a").removeClass("selected");
        jQuery("#of-navigator a").removeClass("selected");
        jQuery("#of-text-content div").removeClass("display");
    }
};

PAR.OperationsHelper = {
    makeRequest: function(pid, content, target) {
        jQuery(target).append('<img class="loader" src="/Media/Images/ajax-loader.gif" alt="Loading" />');
        jQuery(target).animate({
            opacity: 0
        }, 300, function() {
            jQuery.ajax({
                type: "POST",
                url: "/Templates/Public/WebServices/AjaxService.asmx/GetPageContent",
                data: "{'pageid':'" + pid + "','content':'" + content + "','lang':'" + jQuery('html').attr('lang') + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                processData: false,
                cache: false,
                success: function(msg, status) {
                    jQuery(target).remove('.loader');
                    // Replace the div's content with the page method's return.
                    jQuery(target).html(msg.d);
                    jQuery(target).animate({
                        opacity: 1
                    }, 500); 
                },
                error: function(xhr, msg, e) {
                    alert(msg + ', ' + e); //Error Callback
                },
                complete: function(xhr, status) {
                }
            });
        });
    }
};

PAR.GetAreaInfo = function(pid) {
    var innerH = jQuery('#InnerArea').height();
    var e = $('#InnerArea');

    PAR.OperationsHelper.makeRequest(pid, 'body', '#operation-body');
    PAR.OperationsHelper.makeRequest(pid, 'heading', 'h1 .sIFR-alternate');
    setTimeout(function() {
        PAR.OperationsHelper.makeRequest(pid, 'number', '#operation-quote');
    }, 200);
    setTimeout(function() {
        PAR.OperationsHelper.makeRequest(pid, 'image', '#operation-image');
        var heading = jQuery('h1 .sIFR-alternate').text().toUpperCase();
        try {
        sIFR.replacements[0].replaceText(heading, heading);
        } catch(err) {}
    }, 400);
    setTimeout(function() {
        PAR.OperationsHelper.makeRequest(pid, 'table', '#operation-table');
    }, 600);
};

PAR.ImagePresentation = {
    init: function() {
        $("#imagepresentation").addClass("presentationList");
        //$("#imagepresentation .info").css("display", "none");


        // enable tooltip for imagepresentation element
        $("#imagepresentation .bigimage").tooltip({
            effect: 'toggle', //toggle, fade
            tip: 'div.tooltip',
            bounce: false,
            offset: [15, -5]
        });

        //enable trigger for overlay, sets the overlay to the element id set in the rel-attribute.
        $("#imagepresentation .bigimage[rel]").overlay({
            color: '#000',
            left: 'center',
            top: 300,
            // some expose tweaks suitable for modal dialogs
            expose: {
                color: '#000',
                loadSpeed: 400,
                opacity: 0.3
            }
        });

        // image opacity effect
        $('#imagepresentation li .bigimage').css({ 'opacity': 0.5 });


        //hover
        $("#imagepresentation li").hover(function() {
            //image
            $(this).find('.bigimage').animate({ 'opacity': 1 }, 300).css('cursor','pointer');
        },
        function() {
            // onmouseout
            $(this).find('.bigimage').animate({ 'opacity': 0.5 }, 100);
            //        $(this).find('.tooltip').css({ 'display': 'none' });
        });
    }
};

PAR.CorpGovernancePyramid = {
init: function() {

$.fn.maphilight.defaults = {
    fill: true,
    fillColor: 'cccccc',
    fillOpacity: 0,
    stroke: true,
    strokeColor: 'ff0000',
    strokeOpacity: 1,
    strokeWidth: 17,
    fade: true,
    alwaysOn: false
};

// http://davidlynch.org/js/maphilight/docs/
// http://davidlynch.org/blog/2008/03/maphilight-image-map-mouseover-highlighting/
// http://github.com/kemayo/maphilight - IE8 fix
        $("img[usemap]").maphilight();
    }
};

$(document).ready(function() {
    $('#disclaimer').click(function() {
        $('#show, h1').hide();
        $('#hide, h1').show();
    });
    PAR.OilFieldCycle.init();
    PAR.History.init();
    PAR.ImagePresentation.init();
    PAR.CorpGovernancePyramid.init();

});