/*
* name: ui.global.js
* author: RAJF
* notes: global ui functions and config
*/

/*
* ## INTERNAL VARS ##
*/
var _debug;
var _arrowLocation;
var _params = {};
var _attributes = {};
var _flashFileUrl;
var _ie6;
/*
* ## END INTERNAL VARS ##
*/

/*
* ## CONFIG ##
*/
// Log to Firebug Console, set to false for Live!
_debug = true;
_imageLocation = "/images/";
_flashLocation = "/flash/";
// cookie name
_cookiename = "panelSettings"
/* swf object */
_params.scale = "noscale";
_params.salign = "tl";
_params.swliveconnect = "true";
_params.allowscriptaccess = "always";
/*
* ## END CONFIG ##
*/

/*
* window onload function
*/
$(function() {

    // custom font
    Cufon.replace('#main-navigation a', { fontFamily: 'Eurostile' });

    //swfobject.embedSWF(_flashLocation + "home_banner.swf", "banner", "771", "243", "9.0.0", false, {xmlUrl:_flashLocation + "home_banner_config.xml"}, _params, {id:"home_banner"});

    //_ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

    // add corners
    /*if (!_ie6)
    {
    $(".module").not(".whats_new").corner("bottom");
    }*/

    // Tabs
    $('#contact-us ul').show();
    $('#contact-us').tabs().find("h2").hide();

    // add submit class for ie6
    //$('input[type=submit]').addClass("submit");
    /*$('input[type=submit]').addClass("ui-state-default ui-corner-all").hover(
    function(){ 
    $(this).addClass("ui-state-hover"); 
    },
    function(){ 
    $(this).removeClass("ui-state-hover"); 
    }
    );*/

    // remove ui classes for custom tabs
    $('#contact-us').removeClass("ui-widget ui-widget-content ui-corner-all");

    // for some reason, jBreadcrumb gives an 'undefined' error in IE6..
    // i've turned this off for now, until I can sort it out correctly
    // edit: actually.. doing an alert(typeof jBreadcrumb) gives undefined in
    // all browsers.. so newer browsers must be clever enough to catch that error and
    // deal with it accordingly..  
    if (typeof jBreadcrumb != "undefined") {
        $(".breadcrumb").jBreadCrumb({ easing: 'swing', previewWidth: '25' });
    }


});

// log to firebug console
function debug(message) {
    if (_debug) if (window.console) console.log(message);
}

/*
* open windows in external window
*/
function setLinkRel() {
    $('a[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });
}

// blurring on DHTML elements which shouldn't have the dotted outline
// use: $('a.noblur').nb();
$.fn.nb = function() {
    return this.focus(function() {
        this.blur()
    });
}

function setupFlvPlayer(width, height, containerID, thumbURL, flvURL) {
    var params = {};
    params.allowfullscreen = "true";
    if (thumbURL.length > 0) {
        swfobject.embedSWF(_flashLocation + "player_timecode.swf", containerID, width, height, "9.0.0", false, { thumbnail: thumbURL, flvUrl: flvURL }, params, { id: containerID });
    } else {
        swfobject.embedSWF(_flashLocation + "player_timecode.swf", containerID, width, height, "9.0.0", false, { flvUrl: flvURL }, params, { id: containerID });
    }
}

//Add to Global JS File
$(document).ready(function() {
    initTabbedHomeContent();
    //imageLightbox();
});
function initTabbedHomeContent() {
    var tabsPanel = $('.home');
    if (tabsPanel.length > 0) {
        var tabTitles = "";
        $.each($('.tab_container .tab'), function(i) {
            $(this).attr('id', 'tab' + i);
            $(this).addClass("tabsActive");
            tabTitles += '<li><a href="#tab' + i + '"><span>' + $(this).find('h2').eq(0).text() + '</span></a></li>';
        });
        $('.tab_container').prepend('<ul class="tabs">' + tabTitles + '</ul>');
        $(".tab_container .tab, .tab_container .tab h2").hide();
        $("ul.tabs li:first").addClass("first");
        $("ul.tabs li:first").addClass("active").show();
        $(".tab_container .tab:first").show();
        //ON Click Event
        $("ul.tabs li").unbind().click(function() {
            $("ul.tabs li").removeClass("active");
            $(this).addClass("active");
            $(".tab_container > .tab").hide();
            var activeTab = $(this).find("a").attr("hash");
            $(activeTab).show();
            return false;
        });
    }
} 

// Image Lightbox popup

function initGetUrlVar(url) {
    var vars = [], hash;
    var hashes = url.split('?')[1].split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

_lightboxSettings = jQuery.extend({
    overlayBgColor: '#000',
    overlayOpacity: 0.7,
    txtImage: 'Image',
    txtOf: 'of',
    imageLoading: '/themes/global/images/lightbox/loading.gif',
    imageBtnClose: '/themes/global/images/lightbox/lightbox-btn-close.gif',
    imageBtnPrev: '/themes/global/images/lightbox/lightbox-btn-prev.gif',
    imageBtnNext: '/themes/global/images/lightbox/lightbox-btn-next.gif',
    imageBlank: '/themes/global/images/lightbox/lightbox-blank.gif'
}); 
/*
function imageLightbox() {
    var images = $('.wysiwyg > img, #video img, .multimedia img, img#SignpostImage, .signpost img');
    var excludes = $('.EktronAjaxLoading img');
    var filteredImages = images.not(excludes);
    if (filteredImages.length > 0) {
        filteredImages.each(function() {
            var thisImage = $(this);
            if (thisImage.parent('a').length == 0) {
                var linkUrl = thisImage.attr('src');
                if (linkUrl.toLowerCase().indexOf('resizer.ashx') >= 0) {
                    var params = initGetUrlVar(linkUrl);
                    linkUrl = params['i'];
                }
                thisImage.wrap('<a href="http://' + document.domain + linkUrl + '" />');
                thisImage.parent('a').lightBox(_lightboxSettings);
            }
        });
    }
}
*/
