$(document).ready(function(){
						   
	// Dropdown Script	   
	function mainmenu(){
		$("#nav ul ").css({display: "none"}); // Opera Fix
		$("#nav li").hover(function(){
				$(this).find('ul').css({visibility: "visible",display: "none"}).show(400);
				},function(){
				$(this).find('ul').css({visibility: "hidden"});

				/*$(this).find('li').hover(function(){
					$(this).find('ul').css({visibility: "visible",display: "none"}).show(400);
					},function(){
					$(this).find('ul').css({visibility: "hidden"});
				});*/
		});
	}
				
	mainmenu();

 
	
	
	// PNG Fix
	$(document).pngFix(); 	
	
	function mycarousel_itemLoadCallback(carousel, state)
	{
		// Since we get all URLs in one file, we simply add all items
		// at once and set the size accordingly.
		if (state != 'init')
			return;
	
		jQuery.get('http://margielou.com/zp/slider/?width=285', function(data) {
			mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
		});
	};
	
	function mycarousel_itemLoadCallback_small(carousel, state)
	{
		if (state != 'init')
			return;
	
		jQuery.get('http://margielou.com/zp/slider/?width=150', function(data) {
			mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
		});
	};
	
	function mycarousel_itemLoadCallback_gallery(carousel, state)
	{
		//alert("trying");
		if (state != 'init')
			return;
	
		jQuery.get('http://margielou.com/zp/featured/?width=150&gallery=true', function(data) {
			mycarousel_itemAddCallback_gallery(carousel, carousel.first, carousel.last, data);
		});
	};
	
	function mycarousel_itemAddCallback(carousel, first, last, data)
	{
		// Simply add all items at once and set the size accordingly.
		
		data = data.substr(0,data.lastIndexOf("\n") );
		//alert(data);
		var items = data.split('\n');
		
		fisherYates(items);
		//items = items.sort( Math.round(Math.random())-0.5 );
	
		for (i = 0; i < items.length; i++) {
			carousel.add(i+1, items[i]);
			//alert(items[i]);
		}
		
		//alert(items.length);
	
		carousel.size(items.length);
	};
	
	function mycarousel_itemAddCallback_gallery(carousel, first, last, data)
	{		
		data = data.substr(0,data.lastIndexOf("<!--") );
		data = data.substr(0,data.lastIndexOf("|") );
		var items = data.split('|');
		
		fisherYates(items);
	
		for (i = 0; i < items.length; i++) {
			carousel.add(i+1, items[i]);
			//alert(items[i]);
		}
		
		//alert(items.length);
	
		carousel.size(items.length);
	};
	
	// Activate jCarousel
	function mycarousel_initCallback(carousel)
	{
    	// Disable autoscrolling if the user clicks the prev or next button.
    	carousel.buttonNext.bind('click', function() {
    	    carousel.startAuto(0);
    	});
		
    	carousel.buttonPrev.bind('click', function() {
    	    carousel.startAuto(0);
    	});
		
    	// Pause autoscrolling if the user moves with the cursor over the clip.
    	carousel.clip.hover(function() {
    	    carousel.stopAuto();
    	}, function() {
    	    carousel.startAuto();
    	});
	};


    $('#large_slider #mycarousel.jcarousel-skin-atlantica').jcarousel({
    	    auto: 6,
    	    wrap: 'last',
    	    animation: 'slow',
			itemLoadCallback: mycarousel_itemLoadCallback,
    	    initCallback: mycarousel_initCallback
    });
	
	$('#gallery_zp #mycarousel').jcarousel({
    	    auto: 6,
    	    wrap: 'last',
    	    //animation: 'slow',
    	    initCallback: mycarousel_initCallback
    });
	
	$('#gallery_slider #mycarousel').jcarousel({
    	    auto: 6,
    	    wrap: 'last',
    	    animation: 'slow',
			itemLoadCallback: mycarousel_itemLoadCallback_gallery,
    	    initCallback: mycarousel_initCallback
    });
	
	$('#mycarousel.jcarousel-skin-atlantica-small').jcarousel({
    	    auto: 6,
    	    wrap: 'last',
    	    animation: 'slow',
			itemLoadCallback: mycarousel_itemLoadCallback_small,
    	    initCallback: mycarousel_initCallback
    });
		
	$(this).ajaxComplete(function(event,request, settings){
		$("a[rel^='gallery']").prettyPhoto();
	});

		
	// Activate PrettyPhoto Lightbox handle
	$("a[rel^='gallery']").prettyPhoto();

});

function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}