/**
 * --------------------------------------------------------------------
 * Custom Library
 * Version: 0,1, 14.11.2009
 * by Jesse Burcsik, jesseburcsik@gmail.com
 *  
 */

var $j = jQuery.noConflict(); 

function fixPngs(){
        $j(document).pngFix(); 
} 



//This function will coutn up the <li> in a <ul> and randomly display one of them.
// You just pass the 'id' or 'class' of the <ul> containing the <li> you want to display
 function showRandomImg( theDiv ){
	var length = $j( theDiv + " img" ).length;
	var ran = Math.floor(Math.random()*length) + 1;
	$j(theDiv + " img:nth-child(" + ran + ")").addClass('active');
	};



// Make links with href="#" have no changed cursor on hover
function removeCursorChange(){
	$j(".menu[href='#']").css('cursor', 'default');
	$j(".menu[href='#']").attr('onClick', 'javascript: return false');
	
}





// NEW RANDOM SLIDER FOR THE BANNER

// MAKE NEW SLIDER

function slideSwitch() {
    var $active = $j('#banner-images IMG.active');

    if ( $active.length == 0 ) $active = $j('#banner-images IMG:last');

    // use this to pull the images in the order they appear in the markup
	
    //var $next =  $active.next().length ? $active.next()
    //: $('#slideshow IMG:first');
		
    // uncomment the 3 lines below to pull the images in random order
    
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $j( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
}




 // Makes all external links open in a new window
 // as well as links with the class 'target-blank'
function externalLinks(){
$j(function() {
	$j("a[href*='http://']:not([href*='"+location.hostname+"'])").addClass('external-link');
	$j("a[href*='http://']:not([href*='"+location.hostname+"'])").click( function() {	
		window.open(this.href);
		return false;
	});
	$j("a.target-blank").click( function() {	
		window.open(this.href);
		return false;
	});

});
}



//Add spans to first level flyout navs to have IE6 supported rounded corners
function extendVertNav(){

//	addSpanToLinks();
//	addCSStoMenuactive()
	addLiTosubnav();
//	addHomeLink();
//	nonParents(); Not yet working properly, check function.
	
	function addCSStoMenuactive(){
		$j('#top-nav #vertnav .menuactive').parent().css({
			'background' : 'url(/rsrc/images/da-nav-tab-active-main.jpg) no-repeat top left' ,
			'padding' : '0 0 0 10px'
		});
	}
	
	// Change background of Top Level Nav items if they don't have children
		function nonParents(){
			
			$j('.menu').parent().each(
			
			function(){
			if ($j( this ).next('ul').length) { // Next function needs to look for a UL, last attempt did not work
   				return flase;
  			} else {
	    		$j('.menu').addClass("menu-no-sub").removeClass("menu");
  			}
  			});
		}
	
	// Add Home Tab to Main Nav and make it MENUACTIVE if you are on the home page
		function addHomeLink(){
		
		 var siteLocation = window.location.pathname;
		
		if(siteLocation=='http://discoveryair.com/')
			{
			currentData = $j('#vertnav').html();
			$j('#vertnav').empty().append('<li><a class="menu-homeactive" href="index.html">Home</a></li>' + currentData);
			}
			else
			{
			currentData = $j('#vertnav').html();
			$j('#vertnav').empty().append('<li><a class="menu-home" href="index.html">Home</a></li>' + currentData);
			}
		}

	// Add an smpty span inside the top level links (to create rounded corners that work in IE)
	function addLiTosubnav(){
		$j('#vertnav ul').each(
		
			function(){
				currentData = $j( this ).html();
				$j( this ).empty();
	 			$j( this ).append(currentData + '<li class="bottom-subnav">&nbsp;</li>');
	 		}
		);
	}



}

