var sliderImages = 0;
var arrayImages = [];
//Display this function when json finish
function loadImages()
{
	if(jQuery("#slideshow").length == 1)
	{
		sliderImages = 0;
		if(isNaN(sliderImages))
		{
			rotatorImages = 0;
		}
		else
		{
			sliderImages = (sliderImages+1)%(arrayImages.length);				
		}
		//Display 2 Images in front end			
		jQuery('#slideshow').prepend('<img src="'+arrayImages[(sliderImages+1)%arrayImages.length]+'" alt=""/>');
		$intervalid = setInterval( "slideShow()", 15000/2 );
	}
	
}

function slideShow()
{
	var images = jQuery();
	
	jQuery('#slideshow img:last').fadeOut(8000/2, function()
	{
		jQuery(this).remove();
	});

	sliderImages = (sliderImages+1)%(arrayImages.length);
	
	jQuery('#slideshow').prepend('<img src="'+arrayImages[(sliderImages+1)%(arrayImages.length)]+'" alt=""/>');
}
function displayflash()
{
	var flashvars = {};
	flashvars.movieName = "/wp-content/themes/pizza-world/images/pizza-flash_banner-01.swf";
	var params = {};
	params.wmode = "Transparent"
	params.allowscriptaccess = "always";
	var attributes = {};
	swfobject.embedSWF("/wp-content/themes/pizza-world/images/pizza-flash_banner-01.swf", "flash", "820", "190", "9.0.0", false,params);
}
jQuery(document).ready(function(){
	// this initialises the demo scollpanes on the page.
	if(jQuery('#pane').jScrollPane() != "")
	{
		jQuery('#pane').jScrollPane();	
	}
	//load flash
	displayflash();
	
	//get image from JSON	
	jQuery.getJSON(
			"/json-request-image.php",
			function(data){
				jQuery.each(data.userdata, function(i,user){
					arrayImages[i] = user.rotated_image;					
				});
				//call initialImage function to display in front end from javascript
				loadImages();

			}
	);
	//Sub Navigation
	if (jQuery('#menu li').hasClass("current_hover")) {
		jQuery('#menu .current_hover ul').addClass("display-list"); 
	}
	
	// Add a class to the parent li IF it has sub UL's
	jQuery("#menu li:has(ul)").addClass("nav-parent");
	// Add a class to sub-UL if it has a parent LI
	jQuery("#menu li ul").addClass("nav-child");
	
	jQuery("#menu li.nav-parent").each(function(index)
	{
		if(!(jQuery(this).hasClass('current_page_item')) && !(jQuery(this).hasClass('current_page_parent')) && !(jQuery(this).hasClass('current_page_ancestor')))
		{
			// Hide the submenus
			jQuery(this).find("ul").hide();
			
		}
	
		jQuery(this).hover(function ()
		{
			if(!(jQuery(this).hasClass('current_page_item')) && !(jQuery(this).hasClass('current_page_parent')) && !(jQuery(this).hasClass('current_page_ancestor'))){
				
				jQuery(this).addClass("current_hover");
				jQuery(this).addClass("current_item"); 
				jQuery(this).children('.nav-child').stop(true,true).slideDown(400).removeClass("display-list");
				
			}
			
		},
		function ()
		{
				if(!(jQuery(this).hasClass('current_page_item')) && !(jQuery(this).hasClass('current_page_parent'))&& !(jQuery(this).hasClass('current_page_ancestor')))
				{
					
					jQuery(this).children('.nav-child').slideUp(400, function()
					{				    	
						jQuery("#menu li.nav-parent").removeClass("current_item");
				  	});
				  	
			 	}
			}
		);
	});
});
