﻿var startTime = (new Date()).getTime();

$(document).ready(function() {

    $("#logo").pngFix();

    //$("#copyright").append("<a id='website' href='http://triplehelixtech.com' target='_blank'>3HX</a>");

    $("#website").pngFix();


    $("#feedback").fancybox({
        'autoScale': true,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'type': 'iframe'
    });

    //allows the fancybox title display
    $('a').each(function() {
        $(this).attr('ecms_title', $(this).attr('title'));
    });

    $('p[align=center] img').addClass('center');
    $('p[align=right] img').addClass('right');

    $('.twtr-widget').addClass('ui-helper-reset');

    //hover state changes
    $('.ui-state-default:not(#top-menu)').hover(function() {
        $(this).addClass('ui-state-hover');
    }, function() {
        $(this).removeClass('ui-state-hover');
    });

    //hover states on the static widgets
    $('#static, ul.icon li').hover(
	    function() { $(this).addClass('ui-state-hover'); },
	    function() { $(this).removeClass('ui-state-hover'); }
    );

    //random ui goodness
    //$('blockquote').prepend('<span class="ui-icon ui-icon-pin-s right"></span>');
    $('.icrcBlog a').prepend('<span class="ui-icon ui-icon-link right"></span>');

    // ecms Container with title
    $('.ecms_container').addClass('ui-dialog ui-dialog-page ui-widget ui-widget-content ui-corner-all');
    $('.ecms_container_title').addClass('ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix');
    $('.ecms_container_title').prepend('<span class="ui-icon ui-icon-newwin right"></span>');
    $('.ecms_container_content').addClass('ui-dialog-content ui-widget-content');


    // ecms Container
    $('.ecms_container_shadow').addClass('ui-widget-shadow-page ui-corner-all').wrapInner('<div class="ui-tabs" />').wrapInner('<div class="ui-widget ui-widget-content ui-corner-all" />');

    // ecms Accordion
    $('.ecms_accordion .ecms_title').wrapInner("<a href='#'/>");

    $('.ecms_accordion').accordion({
        header: ".ecms_title"
    });

    // ecms Tabs
    $('.ecms_tabs').tabs({ fx: { opacity: 'toggle' }, cookie: { expires: 1} });


    //scroll
    $(".scroll").click(function(event) {
        event.preventDefault();
        var full_url = this.href;
        var parts = full_url.split("#");
        var trgt = parts[1];
        var target_offset = $("#" + trgt).offset();
        var target_top = target_offset.top;
        $('html, body').animate({ scrollTop: target_top }, 900);
    });

    $(".scroll_hov").click(function(event) {
        event.preventDefault();
        var go = $(window).scrollTop() + $(document).height();
        $('html, body').animate({ scrollTop: go }, 7000);
    });

    $(".scroll_top").click(function(event) {
        event.preventDefault();
        $('html, body').animate({ scrollTop: 0 }, 900);
    });


    //message boxes
    $(".message[id]:not('.noClose')").prepend("<ul class='icon ui-widget ui-helper-clearfix right message_close'><li class='ui-state-default ui-corner-all'><a class='closeme' href='#'><span class='ui-icon ui-icon-close'></span></a></li></ul>");

    $(".message_close").click(function(event) {
        event.preventDefault();
        var p = "#" + $(this).parent("div").attr('id');
        if (p.length > 1) {
            var h = ($(p).height() + 10) + "px";
            $(p).animate({ "height": h }, { duration: 400 }).fadeOut("slow");
        } else {
            $(this).parent("div").fadeOut("slow");
        }
    });


    var top = 0;

    $('.scroll_hov').each(function() {
        top = $(this).offset().top;
    });

});

// image was broken, replace with your new image / otherwise use lazyload
$(window).load(function () {
    doDelay();
});

function doDelay() {
    //runs 1secs after window is loaded
    var replaceImg = 'http://' + location.host + '/resources/images/space.gif'
    $('#body-font img').each(function() {
        if (!this.complete || (!$.browser.msie && (typeof this.naturalWidth == "undefined" || this.naturalWidth == 0))) {
            this.src = replaceImg;
            $(this).css({ "display": "none" });
        }
    });
}
function ShowHideSimple(obj) {
    $(obj).animate({ 'height': 'toggle' }, { duration: 900 });
}

function ShowReg(obj) {
    $(obj).animate({ 'height': '50px' }, { duration: 900 });
}

function EndRequestHandler(sender, args) {

}

