/**
 * --------------------------------------------------------------------
 * Custom Library
 * Version: 0,2, 04.03.2010
 * by Jesse Burcsik, jesseburcsik@gmail.com
 *  
 */

var $j = jQuery.noConflict(); 

function fixPngs(){
        $j(document).pngFix(); 
} 


// 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 empty span to bottom of hover
	function addSpanTosideNav(){
		$j('#sidenav > a + span > a + span').each(
		
			function(){
				currentData = $j( this ).html();
				$j( this ).empty();
	 			$j( this ).append(currentData + '<div class="extra-subnav">&nbsp;</div>');
	 		}
		);
	}


//Add spans to first level flyout navs to have IE6 supported rounded corners
function extendVertNav(){

	//	addSpanToLinks();
	addCSStoMenuactive();
	// addLiTosubnav();
	hoverParent();
	hoverSimpleNav();
	hoverSimpleNavMoar();
	markNavWithKids();
	markFullNavWithKids();
	
	
	
function markNavWithKids(){
	//custyScript('#vertnav a.menu').css('background','red');
	custyScript('#vertnav a.menu, #vertnav a.menuactive').siblings('ul').prev().addClass('has-kids');
	custyScript('#sidenav a[class^="submenu"]').next('span').prev().addClass('has-kids');
}


function markFullNavWithKids(){
	custyScript('ul#full-nav li a').siblings('ul').prev().addClass('has-kids');
}
	
	function hoverSimpleNav(){
		
		// First hide the active menu
		$j('#sidenav > a + span > a + span').hide();
	
		$j('#sidenav > a + span > a').hover(
			function(){
				$j( this ).addClass('hovered');
				$j( this ).next().addClass('is-being-hovered');
			},
			function(){
				$j( this ).removeClass('hovered');
				$j( this ).next().removeClass('is-being-hovered');
			}
		);
	}

	function hoverSimpleNavMoar(){
		$j('#sidenav > a + span > a + span').hover(
			function(){
				$j( this ).prev().addClass('hovered');
				$j( this ).addClass('is-being-hovered');
			},
			function(){
				$j( this ).prev().removeClass('hovered');
				$j( this ).removeClass('is-being-hovered');
			}
		);
	}


	
	
	function addCSStoMenuactive(){
		$j('#vertnav .menuactive').parent().css({
			'background' : 'url(/rsrc/apes/images/apes-head-vertnav-hover-active.jpg) no-repeat top left' ,
			'padding' : '0 0 0 10px'
		});
	}
	
	// make the parent :sudo hovered as its child is being hovered
	function hoverParent(){
		$j('#full-nav li a + ul').hover(
			function(){
				$j( this ).prev().addClass('is-being-hovered');
			},
			function(){
				$j( this ).prev().removeClass('is-being-hovered');
			}
		);
	}
	
/* TO DELETE	
	$j("td").hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);
TO DELETE */

	// 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>');
	 		}
		);
	}



}

/*  
	DOCUMENTATION ::

   This plugin is used to display a set amount (defaults to one) of child elements.

  randomDisplayer({amount:x})

  Example call would be:
  	$('#featured-product').randomDisplayer({amount:3});

  To show only one you do not need to define 'amount'.
  Example:
	$('#featured-product').randomDisplayer();
		
*/

(function($) {
  $.fn.randomDisplayer = function(options) {
  
  	var opts = $.extend({}, $.fn.randomDisplayer.defaults, options);
  
    return this.each(function() {
		var theElements = jQuery( this ).children();
        jQuery( this ).empty();
        for(i=0 ;i<opts.amount;i++){
			var random = theElements.get(Math.floor(Math.random()*theElements.length));
			var theInstance = jQuery.inArray(random,theElements);
        	var theElements = theElements.not(theElements[theInstance]);
        	jQuery( this ).append(random);
        }
   });
  }
  
   $.fn.randomDisplayer.defaults = {amount: 1}
  
})(jQuery);



function checkErr(){
		$j('#highlights ul li').each(function() {
   		var theErr = $j(this).text();
 //		alert(theErr);
   		$j('[name='+theErr+']').addClass('input-err');
        //$j('[name='+theErr+']').prev('label').addClass('input-err');
        //$j('[name='+theErr+']').prev('span').addClass('input-err');

		});
        setTimeout('checkErr()', 500);
}

/*function formErrors(){
    $j("input[value='Ajouter']").click(function(){
        //setTimeout('checkErr()', 2000);
        // setTimeout('checkErr()', 3000);
	});

}*/

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// Reverse NoScript
$j(document).ready(function() {
    $j('.scriptOnly').show();
});

