/**
 * --------------------------------------------------------------------
 * Custom Library
 * Version: 0,1, 14.11.2009
 * by Jesse Burcsik, jesseburcsik@gmail.com
 *  
 */

 	var $j = jQuery.noConflict(); 

	function fixPngs(){
        $j(document).pngFix(); 
	} 


// ispeople() is a validator for the contact form

function peopleTest(){
	$j('#feedback').submit(
		function(){
			if( $j('#ispeople').val() == 4 ){
				return true;
			}else{
				$j('#ispeople').css('background-color' , '#fdedf0');
				return false;
			}
		}
	);
	
	$j('#ispeople').focus(function() {
		$j( this ).css('background-color','#ffffff');
		});
}



// Make 'Media Center' Main Nav item link to Discovery Air news - Under construction
function addLink(cDataOfLink, url){

	return false;
	
}

// 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');
	
}


//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 showRandomLi( theDiv ){
	var length = $j( theDiv + " li" ).length;
	var ran = Math.floor(Math.random()*length) + 1;
	$j(theDiv + " li:nth-child(" + ran + ")").show();
	};


//Envoke the Slider
  function formatText(index, panel) {
		  return index + "";
	    }


function makeSlider(){   
        $j(function () {
        
            $j('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 8000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 600,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "Play",             // Start text
		        stopText: "Stop",               // Stop text
		        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
            });
            
            $j("#slide-jump").click(function(){
                $j('.anythingSlider').anythingSlider(6);
            });
            
        });
        }


 // 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;
	});

});
}


// Makes a Simple expando for the Pictures Section, or any other thats needed
function initPictureExpando() {
	$j('.expando-container').children('div').hide();
//	$j('.expando-container').children('div:first').show();
//	$j('.expando-container h3:first').addClass('active-expando');
	$j('.expando-container h3').click(
		function() {
			$j(this).next().slideToggle('normal');
			$j( this ).toggleClass("active-expando");
		}
	);
}



// Remove the vert.css style sheet //
function removeVertCSS(){
	$j("link[href='/common/css/vert.css']").remove();
	$j("link[href='/common/css/vertie7.css']").remove();
	$j("link[src='/common/js/flymenu.js']").remove();
} 

// Add a Span to the end of links with a specific class to make them dynamic rounded corners
	
	function linksToButtons(){
		$j('.button-link').each(
	
		function(){
	
		currentData = $j( this ).html();
	
		$j( this ).empty();
		$j( this ).append( currentData + '<span>&nbsp;</span>');
	
		}
	
		);
	}


//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('#top-nav #vertnav').html();
			$j('#top-nav #vertnav').empty().append('<li><a class="menu-homeactive" href="/">Home</a></li>' + currentData);
			}
			else
			{
			currentData = $j('#top-nav #vertnav').html();
			$j('#top-nav #vertnav').empty().append('<li><a class="menu-home" href="/">Home</a></li>' + currentData);
			}
		}

	// Add an smpty span inside the top level links (to create rounded corners that work in IE)
	function addLiTosubnav(){
		$j('#top-nav #vertnav ul').each(
		
			function(){
				currentData = $j( this ).html();
				$j( this ).empty();
	 			$j( this ).append(currentData + '<li class="bottom-subnav">&nbsp;</li>');
	 		}
		);
	}



}
