/**
 * @author dean halford
 * 
 * modifyMenu - take the current menu system and re-arrange it a bit
 */

var modifyMenu = function(){
	var newMenu = $('#newMenu');
	//var newlinks = ['<span id="home-link"><a href="index.php">sacha hurley</a></span>'];
	/*$(".section-title").each(
		function(i, obj){
			var h = $(obj).html();
			newlinks.push("<a href=\"/ppsite/"+h+"/"+h+"-listing/\">"+h+"</a>");			
		}
	);  */
	
	
	
	$("#img-col div:first").hide();  // hide our thumbnail img
	
	$("#img-col div:gt(10)").hide();

	if($("#img-col div:eq(11)").length > 0){
		$("#img-col").append("<p id='morelink'><a href='javascript:seeMoreImages();'>See More</a></p>")
	}
	
	var newlinks = new Array();
	$('#custom-menu div').each(function(i,obj){newlinks.push(obj.innerHTML)});
	for(var i=0; i< newlinks.length / 4; i++){
		newMenu.append('<div class="menu-section ms'+i+'">'+newlinks.slice(i*4, i*4+4).join('')+'</div>');
	}
	
	var menuItems = $("#menu ul").hide();
	
	
//	$('#newMenu a').each(function(i){
//		$(this).bind('mouseenter', function(){showMenuItem(i-1)});
//		$(this).bind('mouseleave', function(){hideMenuItem(i-1)});
//	});
	
}

/**  A JQuery delay function */
$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

var seeMoreImages = function(){
	$("#img-col div:gt(10)").slideDown('slow');
	$("#morelink").html("<a href='javascript:hideMoreImages();'>See Less</a>");
}

var hideMoreImages = function(){
	$("#img-col div:gt(10)").slideUp();
	$("#morelink").html("<a href='javascript:seeMoreImages();'>See More</a>");
}

var showMenuItem = function(index){
	if (index >= 0) {
		var menuItems = $("#menu ul");
		$(menuItems[index]).show();
	}
}

var hideMenuItem = function(index){
	if ( index >= 0)
		$($("#menu ul")[index]).delay(500, function(){
			$(this).hide();
		});
}
