if(typeof this.PINT==="undefined"){var PINT={}; }

/* FUNCTIONS *******************/

/* ADD CLASS **********/
// Format: $('.something').PINT_addClass('last');
$.fn.PINT_addClass = function(addClass) {
    var localThis = $(this);
    if ( localThis.length ) {
        localThis.addClass(addClass);
    }
};

/* FOCUS/BLUR **********/
$.fn.PINT_focusBlur = function(text,isPasswordField) {
    var localThis = $(this);
    if ( localThis.length ) {
        localThis.focus(function(){ 
            if (localThis.val() == text) {
                localThis.val('')
                if (isPasswordField) this.type = 'password';
            }
        }).blur(function(){ 
            if (localThis.val() == '') {
                if (isPasswordField) this.type = 'text';
                localThis.val(text);				
            }
        });
    }
};

/* PNG24 'FIX' FOR IE6 **********/
// IE6 doesn't support transparency for PNG24 images. This code corrects that.
// Note: this is not jQuery and should be included for IE6 support
PINT_pngFix = function() {
    var PINT_browser = navigator.userAgent.toLowerCase();
    if ( (PINT_browser.indexOf("msie 6.")!==-1) && (PINT_browser.indexOf("opera")===-1) ) {
        for (var i=0; i<document.images.length; i++) {
            var img = document.images[i]; var imgName = img.src.toUpperCase();
            if ( imgName.substring(imgName.length-3,imgName.length) == "PNG" ) {
                var imgID=img.id ? "id='"+img.id+"' ":""; var imgClass=img.className ? "class='"+img.className+"' ":""; var imgTitle=img.title ? "title='"+img.title+"' ":"title='"+img.alt+"' "; var imgStyle="display:inline-block;"+img.style.cssText;
                
                if (img.align=="left") imgStyle="float:left;"+imgStyle;
                if (img.align=="right") imgStyle="float:right;"+imgStyle;
                if (img.parentElement.href) imgStyle="cursor:hand;"+imgStyle;
                
                var strNewHTML="<span "+imgID+imgClass+imgTitle+"style=\""+"width:"+img.width+"px; height:"+img.height+"px;"+imgStyle+"; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+img.src+"\',sizingMethod='scale');\"></span>";
                img.outerHTML=strNewHTML;i=i-1;
            }
        }
    }
};

/* FLASH CODE **********/
$.fn.PINT_flash = function(tgtPath,tgtWidth,tgtHeight,tgtFlashvars) {
    if ( $(this).length ) {
        var flashvars = tgtFlashvars || false;
        var flashvarsParam = '<param name="flashvars" value="'+flashvars+'" />';
        var flashvarsEmbed = 'flashvars="'+flashvars+'"';
        if ( !flashvars.length ) {
            flashvarsParam = '';
            flashvarsEmbed = '';
        }
        $(this).html(
            [
               '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+tgtWidth+'" height="'+tgtHeight+'" id="butterfly" align="middle">',
               '    <param name="allowScriptAccess" value="sameDomain" />',
               '    <param name="allowFullScreen" value="false" />',
               '    <param name="movie" value="'+tgtPath+'" />',
               '    <param name="quality" value="high" />',
               '    <param name="wmode" value="transparent" />',
               '    <param name="loop" value="false" />',
                    flashvarsParam,
               '    <embed src="'+tgtPath+'" quality="high" width="'+tgtWidth+'" height="'+tgtHeight+'" loop="false" name="butterfly" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" '+flashvarsEmbed+' pluginspage="http://www.macromedia.com/go/getflashplayer" />',
               '</object>'
            ].join('')
        );
    }
};

/* 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 localThis = $(this);
    if ( localThis.length ) {
        // Find each TAB instance on the page
        localThis.each(function(tabsIndex, tabsElement){
            // Add a class only if JS enabled. Allows for tabbox top-margin
            localThis.addClass('tabs-jsenabled').find('.tab-title').hide();
        
            var tabs = localThis.children('.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 localThis = $(this);
                var thisID = localThis.attr('id'); // Get tabbox ID
                var thisChildren = localThis.children().children('.tab-title'); // Get tabbox HTML
                var selected = (index == 0) ? ' class="ui-tabs-selected"' : '';  // Sets which tab starts 'on'
                
                // Add <li>s to the UL per tabbox
                ul.append('<li'+selected+'><a href="#'+thisID+'"><span>'+thisChildren.html()+'</span></a></li>');
            });
            
            // Add the <ul> to the TAB instance
            localThis.prepend(ul);
        });
        localThis.tabs();
    }
};
*/

/* FANCYBOX **********/
$('.pintbox').fancybox({ 'titleShow':false });
$('.pintbox-iframe').fancybox({ 'width':'75%','height':'75%','autoScale':false,'transitionIn':'fade','transitionOut':'fade','type':'iframe'});

/* INITIALIZE FUNCTIONS *******************/
PINT.init = function() {

    /* JS ENABLED - Target any element differently (CSS) if JS enabled/disabled **********/
    $('body').PINT_addClass('js-enabled');

    /* INPUT: 'FOCUS/BLUR' **********/
    $('.input-search').PINT_focusBlur('Search');

    /* PNG24 'FIX' FOR IE6 ********/
    PINT_pngFix();
    
    /* TABS **********/
    //$('.tabs').PINT_tabs();

    /* SITE FLASH ********/
    $('.banner-patient').PINT_flash('/assets/flash/PATIENT_BEPR21_HPb2.swf',980,327);
    $('.banner-physicians').PINT_flash('/assets/flash/PHYSICIAN_BEPR21_HPb.swf',980,327);

	/* FANCYBOX OVERLAY ( in init() )**********/
	//$('.pintbox').PINT_overlay();
};

/* RUN FUNCTIONS *******************/
$(document).ready(function() {
  PINT.init();
});
