/**
 * @version $id: common.js, v1.0 2008/02/20 00:27:33 GMT+0800 $
 * @author Jerome Coloma <jeromecoloma@gmail.com>
 * @copyright Copyright (c) 2007-2008, Frozynart Designs
 * @since Version 1.0
 */


if(!window.console||!console.firebug){var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];window.console={};for(var i=0;i<names.length;++i){window.console[names[i]]=function(){}}}

var blank = new Image();
blank.src = ABS_URI_TRAIL+'lib/css/blank.gif';

// function fixPng(png) { var src = png.src;  if (!png.style.width) { png.style.width = $(png).width(); } if (!png.style.height) { png.style.height = $(png).height(); } png.onload = function() { }; png.src = blank.src; png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')"; }

jQuery.fn.homeGallery = function( options ) {
    var settings = {
        selectedIndex:null,
        callback:null
    };
    
    var _banners              = [];
    var _lastSelectedBanner   = null;
    
    if( options ) { jQuery.extend( settings, options ); }
    jQuery(this).append('<div id="home_banner_active_bg"></div>');
    jQuery('.banner',this).each(function(index) {
        
        jQuery(this).css({position:'absolute',zIndex:'50',top:index*45+(25), right:0});

        jQuery('.description',this).addClass('inactive');
        _banners.push( {
            obj:jQuery(this),
            title:jQuery('.title',this),
            description:jQuery('.description',this)
        } );
        
        
        
        jQuery('.title a',this).append(' &raquo;').attr('href','javascript:void(0);').click(function(){
            
            if( _lastSelectedBanner ) {
                _lastSelectedBanner.removeClass('selected').animate({
                    fontSize:'1.0em'
                });
            }
            
            jQuery(this).addClass('selected').animate({
                fontSize:'1.4em'
            });
            jQuery('#home_banner_active_bg').fadeOut('slow').fadeIn('slow').html(_banners[index].description.html());
            
            _lastSelectedBanner = jQuery(this);
            
            if(settings.callback && 'function' == typeof(settings.callback)) {
                settings.callback();
            }
            
            return;
        });
        
        
    });
    
    if( !isNaN(settings.selectedIndex) ) {
        jQuery('.title a', this).eq(settings.selectedIndex).click();
    }
    return jQuery(this);
};


jQuery(document).ready( function() {
                            

    jQuery(window).load( function(){
        
        if (jQuery('#home-banners > #banner-thumbnails').frozAutoCenter) {
            jQuery('#home-banners > #banner-thumbnails').frozAutoCenter({
                verticalCenter: true,
                relativeTo: '#home-banners > #main-banners > li:first'
            });
        }
        
        if (jQuery('#home-banners > #main-banners').frozThumbSlider) {
            jQuery('#home-banners > #main-banners').frozThumbSlider({
                thumbList: '#banner-thumbnails',
                hoverOption: true,
                hoverBox: '#banner-thumbnails-hover-box',
                slideVertical: true,
                boxOffsetLeft: 0,
                boxOffsetTop: 0,
                thumbsVertical: true,
                autoSlide: 5000
            });
        }
        
    });
    // Fix PNG
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    // if (badBrowser) { jQuery('img[src$=.png]').each(function() { if (!this.complete) { this.onload = function() { fixPng(this) }; } else { fixPng(this); } }); }
    
    // Common
    jQuery('a[rel="_blank"],area[rel="_blank"]').attr('target','_blank');
    jQuery('a[href=#]').attr({href:'javascript:void(0);'});
    jQuery('.clean-email').defuscate();
    
    
    jQuery('.e-l').each(function(i){
        var _this  = jQuery(this);
        var _class = _this.attr('class');
        jQuery('<a href="'+ _this.attr('title') +'" target="_blank" class="'+ _class +'">'+ _this.text() +'</a>').replaceAll(_this);
    });
    
    jQuery('.froz-accordion').frozAccordion({collapsedClassName:'nocollapse'});

    // Search Box
    var _defaultSearchValue = 'search for...';
    jQuery('#q').val(_defaultSearchValue).focus(function(){
        if( jQuery(this).val() == _defaultSearchValue ) {
            jQuery(this).val('');
        }
    }).blur(function(){
        if( jQuery(this).val() == '' ) {
            jQuery(this).val(_defaultSearchValue);
        }
    });
    
    // Lightbox Default Option
    var lightBoxOption = {
        overlayOpacity: 0.8,
        imageBlank:    ABS_URI_TRAIL+'lib/css/jquery/lightbox/lightbox-blank.gif',
        imageLoading:  ABS_URI_TRAIL+'lib/css/jquery/lightbox/lightbox-ico-loading.gif',
        imageBtnClose: ABS_URI_TRAIL+'lib/css/jquery/lightbox/lightbox-btn-close.gif',
        imageBtnPrev:  ABS_URI_TRAIL+'lib/css/jquery/lightbox/lightbox-btn-prev.gif',
        imageBtnNext:  ABS_URI_TRAIL+'lib/css/jquery/lightbox/lightbox-btn-next.gif'
    };
    
    jQuery("a[class^=lightbox-menu-ad1]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad2]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad3]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad4]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad5]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad6]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad7]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-menu-ad8]").lightBox(lightBoxOption);
    
    for(var i=1; i<=30; i++) {
        jQuery("a[rel=lightbox-event-ad" + i + "]").lightBox(lightBoxOption);
    }
    
    
    jQuery("a[rel='lightbox']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxPull']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxJfest']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxRelay']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxEaster']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxDiego']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxLivingExpo']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxRockBands']").lightBox(lightBoxOption);
    jQuery("a[rel='lightboxHin']").lightBox(lightBoxOption);
    
    
    jQuery("a[class^=lightbox-ad1], area[class^=lightbox-ad1]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad2], area[class^=lightbox-ad2]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad3], area[class^=lightbox-ad3]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad4], area[class^=lightbox-ad4]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad5], area[class^=lightbox-ad5]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad6], area[class^=lightbox-ad6]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad7], area[class^=lightbox-ad7]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad8], area[class^=lightbox-ad8]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad9], area[class^=lightbox-ad9]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad11], area[class^=lightbox-ad10]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad12], area[class^=lightbox-ad11]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad13], area[class^=lightbox-ad12]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad14], area[class^=lightbox-ad13]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad15], area[class^=lightbox-ad14]").lightBox(lightBoxOption);
    jQuery("a[class^=lightbox-ad16], area[class^=lightbox-ad15]").lightBox(lightBoxOption);
        // 
       // var homeGalleryOnClick = function() {
       //  jQuery('#home_banner_active_bg ul.details').css('height',0).animate({height:38 }, 900);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad1]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad2]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad3]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad4]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad5]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad6]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad7]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad8]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad9]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad10]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad11]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad12]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad13]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad14]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad15]").lightBox(lightBoxOption);
       //  jQuery("#home_banner_active_bg a[class^=lightbox-ad16]").lightBox(lightBoxOption);
       // };
    
    // Homepage Banner
    // jQuery('#home_banners').homeGallery({selectedIndex:0,callback:homeGalleryOnClick});
    
    if (badBrowser) {
        
        jQuery("ul.nav").supersubs({ 
                minWidth:    15,   
                maxWidth:    100, 
                extraWidth:  0 
            }).superfish().find('ul').bgIframe({opacity:false, width:140}); 
            
    } else {
        jQuery("ul.nav").supersubs({ 
                minWidth:    15,   
                maxWidth:    100, 
                extraWidth:  0 

            }).superfish(
                /*{animation : { opacity:0.96, height:'show'}}*/
            )
            .find(">li:has(ul)")
                .mouseover(function(){
                    $("ul", this).bgIframe({opacity:false});
                })
                .find("a")
                    .focus(function(){
                        $("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
        });
    }
    
                
    
    /**
     * Phone Tabs
     */
    //jQuery('.phones-tabs > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });    
    
    
    
    
    /**
     * Custom Accordion
     */
     
    var __lastSelectedListMenu = null;
    //jQuery( '.menu > li > a' ).not( ':first' ).find( '+ ul' ).slideUp( 800 );
    jQuery( '.menu li:has(ul) > a' ).addClass('collapsed');
    jQuery( '.menu > li > a' ).find( '+ ul' ).slideUp( 800 );
    jQuery( '.menu li a' ).filter(
        function(index) {
            //console.log(index);
            var currentPage   = unescape(location.pathname);
            var href          = jQuery( this ).attr('href');
            //console.log( currentPage + ' : ' + href );    
            //jQuery( this ).parent('li').addClass('collapsed');
            if( href == currentPage ) {
                    /*console.log( href + ' : ' + currentPage );*/
                jQuery( this ).addClass( 'selected' ).parent('li').addClass('selected').hover(
                    function() {
                        jQuery(this).addClass( 'selected' );
                        jQuery('a', this).addClass( 'selected' );
                    },
                    function() {
                        jQuery(this).addClass( 'selected' );
                        jQuery('a', this).addClass( 'selected' );
                    }
                );
                //console.log( jQuery( this ).parent() );
                if( !jQuery( this ).parent().parent('.menu').length ) {
                    jQuery( this ).parent().parent().slideToggle( 'slow' );
                } else {
                    
                }
                //console.log(jQuery(this).parent().parent().parent('li a'));
                //jQuery(this).parent().parent().parent('li > a').removeClass('collapsed').toggleClass('expanded');
                //console.log( jQuery(this).parent().parent().parent('>a') );
            }
        }
    ); 
    
    var closeAllJQMenu = function( ) {
        jQuery( '.menu > li > a' ).find( '+ ul' ).slideUp( 'slow' );
    };
    jQuery( '.menu > li > a' ).click(
        function() {
            closeAllJQMenu( );
            jQuery( this ).find( '+ ul' ).slideToggle( 'fast' );
            //.animate({opacity: 0}, 0.1).animate({opacity: 1.0}, 1500)
        }
    );
                                                                
} );


    


// Added 2009-10-30
// To Prevent Errors on All Pages that's not using the Gallerific
// This can be removed later when MSI Promo is done
if(jQuery('#gallery').galleriffic) {


    // We only want these styles applied when javascript is enabled
    jQuery('div.navigation').css({'width' : '300px', 'float' : 'left'});
    jQuery('div.content').css('display', 'block');

    // Initially set opacity on thumbs and add
    // additional styling for hover effect on thumbs
    var onMouseOutOpacity = 0.67;
    jQuery('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
        .hover(
            function () {
                jQuery(this).not('.selected').fadeTo('fast', 1.0);
            }, 
            function () {
                jQuery(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
            }
        );

    jQuery(document).ready(function() {
        // Initialize Advanced Galleriffic Gallery
    
        var galleryAdv = jQuery('#gallery').galleriffic('#thumbs', {
            delay:                  2000,
            numThumbs:              12,
            preloadAhead:           10,
            enableTopPager:         true,
            enableBottomPager:      true,
            imageContainerSel:      '#slideshow',
            controlsContainerSel:   '#controls',
            captionContainerSel:    '#caption',
            loadingContainerSel:    '#loading',
            renderSSControls:       true,
            renderNavControls:      true,
            playLinkText:           'Play Slideshow',
            pauseLinkText:          'Pause Slideshow',
            prevLinkText:           '&lsaquo; Previous Photo',
            nextLinkText:           'Next Photo &rsaquo;',
            nextPageLinkText:       'Next &rsaquo;',
            prevPageLinkText:       '&lsaquo; Prev',
            enableHistory:          true,
            autoStart:              false,
            onChange:               function(prevIndex, nextIndex) {
                jQuery('#thumbs ul.thumbs').children()
                    .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                    .eq(nextIndex).fadeTo('fast', 1.0);
            },
            onTransitionOut:        function(callback) {
                jQuery('#caption').fadeTo('fast', 0.0);
                jQuery('#slideshow').fadeTo('fast', 0.0, callback);
            },
            onTransitionIn:         function() {
                jQuery('#slideshow').fadeTo('fast', 1.0);
                jQuery('#caption').fadeTo('fast', 1.0);
            },
            onPageTransitionOut:    function(callback) {
                jQuery('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
            },
            onPageTransitionIn:     function() {
                jQuery('#thumbs ul.thumbs').fadeTo('fast', 1.0);
            }
        });
    });


}

    
swfobject.embedSWF( ABS_URI_TRAIL + 'flash/ninth-design-ad.swf', 'ninth_design_ad', '200', '180', '9.0.0', ABS_URI_TRAIL + 'lib/js/swfobject/expressInstall.swf', {menu: 'false', scale:'noScale', wmode:'transparent'}, {id: 'ninth_design_inner_ad', name: 'ninth_design_inner_ad'} );

