if(typeof this.PINT==="undefined"){var PINT={};}

/* FUNCTIONS *******************/

(function ($) {

    /** ADD CLASS *****/
    // Format: $('.something').PINT_addClass('last');
    $.fn.PINT_addClass = function(addClass) {
        this.each(function() {
            $(this).addClass(addClass);
        });
    };

    /** FADER BANNER **********/
    $.fn.PINT_faderControls = function() {
        this.each(function() {
            var galleryControls = '<div class="banner-controls clearfix"><div class="clearfix"></div></div>';
            var cornerCode = '<span class="banner-corner banner-corner-bl"></span><span class="banner-corner banner-corner-br"></span>';
            $(this)
                .append(galleryControls+cornerCode)
                .children('ul:first-child')
                    .cycle({
                        fx: 'fade',
                        speed: 4500,
                        timeout: 7000,
                        pager: '.banner-controls div',
                        next: '#next', 
                        prev: '#prev',
                        pause: true,
                        easing: 'easeOutExpo' // set easing with values found in this linked jquery min (we've embeded) or include easing.js
                    })
            ;
        })
    };
    
    /** FOCUS/BLUR *****/
    $.fn.PINT_focusBlur = function() {
        this.each(function() {
            var text = $(this).attr('value');
        
            $(this)
                .focus(function(){
                    if ( $(this).val() == text ) {
                        $(this).val('')
                        if ( $(this).hasClass('input-password') ) this.type = 'password';
                    }
                }).blur(function(){ 
                    if ( $(this).val() == '' ) {
                        if ( $(this).hasClass('input-password') ) this.type = 'text';
                        $(this).val(text);				
                    }
                })
            ;
        });
    };
    
    /** TABS **********/
    // Write out the tabs in JS so that w/ JS disabled we don't show buttons that don't work!
    $.fn.PINT_tabs = function() {
        var counter = 0;
        // Find each TAB instance on the page
        this.each(function(tabsIndex, tabsElement){
            var eachThis = $(this);
            // Add a class only if JS enabled. Allows for tabbox top-margin
            eachThis.addClass('tabs-jsenabled').find('.tab-title').hide();
        
            var tabs = eachThis.children('div.tabbox'); // Get tabboxs
            var ul = $('<ul class="tab-links"></ul>'); // Create UL links only when JS enabled
            
            // For each tabbox we're going to create corresponding <li>
            tabs.each(function(index, element){
                var eachThis = $(this);
                var thisID = eachThis.attr('id'); // Get tabbox ID
                var thisChildren = eachThis.children('.tab-title'); // Get tabbox HTML
                var last = (counter+1 == tabs.length) ? 'ui-tabs-last ' : '';  // Sets which tab starts 'on'
                var selected = (index == 0) ? 'ui-tabs-selected' : '';  // Sets which tab starts 'on'
                
                // Add <li>s to the UL per tabbox
                ul.append('<li class="'+last+selected+'"><a href="#'+thisID+'">'+thisChildren.html()+'</a></li>');
                counter++;
            });
            
            // Add the <ul> to the TAB instance
            eachThis.prepend(ul);
        });
        if ( this.length ) {
            this.tabs();
        }
    };
	
	/** PIPELINE TOOL TIP *****/
    $.fn.PINT_tip = function() {
        this.each(function() {
			//console.log(this);
			//$(this).next('.desc').toggle();
            $(this)
                .hover(function(){
					$(this).next('.desc').toggle();			
				})
            ;
        });
    };

}(jQuery));


/* INITIALIZE FUNCTIONS *******************/
PINT.init = function() {

    /** JS ENABLED - Target any element differently (CSS) if JS enabled/disabled *****/
    $('body').PINT_addClass('js-enabled');

    /** FADER GALLERY *****/
    $('div.banner').PINT_faderControls();
    
    /** INPUT: 'FOCUS/BLUR' *****/
    $('input.input').PINT_focusBlur();
    
    /** TABS *****/
    $('div.tabs').PINT_tabs();
	
	/** PIPELINE TOOL TIP *****/
    //$('#tbl-pipe .prog a').PINT_tip();

};

/* RUN FUNCTIONS *******************/
$(document).ready(function() {
  PINT.init();
});
