$(document).ready(function(){
	
	//LIGHTBOX INTITIALIZE
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'slow', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
	});
	
	//CUFON FONT REPLACEMENT
	Cufon.replace('#title h1, h2, h3', { fontFamily: 'Roel' });
	
	//PLACES NEARBY ACCORDIAN
	$('.accordian li').find('ul').hide();
	$('.accordian li').click(function() {
		$(this).find('ul').animate({
			height: "toggle"
		}, 'fast');
		$(this).toggleClass('open');
	})
	
	/*****************************************************************************************************************/
	/*******                            MAIN NAVIAGTION DROP DOWN                             ************************/
	/*****************************************************************************************************************/
	
	//HIDE THE DROPDOWNS
	$('.dd').hide();
	
	//WHEN YOU ROLL OVER MENU WITH DROPDOWN
	$('.sub').hover(function() {
		//alert('hello');
		$(this).find('.dd').fadeIn()
	}, function() {
		//do nothing
	});
	
	//WHEN YOU ROLL OFF DROPDOWN
	$('.dd').hover(function() {
		//do nothing
	}, function() {
		$('.dd').fadeOut()
	});
	
	//WHEN YOU ROLLL OVFF THE MENU
	$('#nav-main').hover(function() {
		//$(this).next('.dd').show()
	}, function() {
		//	alert('hello world')
		$('.dd').fadeOut()
	});
	
	$('.thingstodo').hover(function() {
		//$(this).next('.dd').show()
			$('.placestostay').next('.dd').fadeOut();
					
	}, function() {
			$('.placestostay').next('.dd').fadeOut();
	});
	
	$('.placestostay').hover(function() {
		//$(this).next('.dd').show()
			$('.thingstodo').next('.dd').fadeOut();
			$('.travelguide').next('.dd').fadeOut();

		
	}, function() {
			$('.thingstodo').next('.dd').fadeOut();
			$('.travelguide').next('.dd').fadeOut();

	});
	
	$('.travelguide').hover(function() {
		//$(this).next('.dd').show()
			$('.placestostay').next('.dd').fadeOut();
			$('.thelatest').next('.dd').fadeOut();
					
	}, function() {
			$('.placestostay').next('.dd').fadeOut();
			$('.thelatest').next('.dd').fadeOut();
	});
	
	$('.thelatest').hover(function() {
		//$(this).next('.dd').show()
			$('.travelguide').next('.dd').fadeOut();
			$('.regions').next('.dd').fadeOut();
					
	}, function() {
			$('.travelguide').next('.dd').fadeOut();
			$('.regions').next('.dd').fadeOut();
	});
	
	$('.regions').hover(function() {
		//$(this).next('.dd').show()
			$('.thelatest').next('.dd').fadeOut();
					
	}, function() {
			$('.thelatest').next('.dd').fadeOut();
	});


	/*****************************************************************************************************************/
	/*******                                        HOMEPAGE TABS                             ************************/
	/*****************************************************************************************************************/
	$('.item-container').find('.acc').hide();
	$('.item-container').find('.rest').hide();
	$('.item-container').find('.events').hide();
	$('.item-container').find('.blog').hide();

	$('#home #nav-sub li').click(function() {
		var myID = $(this).attr('id');
		
		clearHomeTab();
		$(this).find('a').addClass('selected');
		$('.item-container').find('.' + myID).fadeIn();
	})
	
	/*****************************************************************************************************************/
	/*******                                        SLIDESHOW START                             **********************/
	/*****************************************************************************************************************/
//	rotatePics(1);
	//setSlideShow('entry');
	
	$("#slideshow").PikaChoose();
	
	getPath();
	
});

function getPath() {
	
	var tempURL = document.location;
	var tempArray = String(tempURL).split("/");
	
	if (tempArray[3]!=""||tempArray!="undefined") {
		$('#pikame').PikaChoose();
	} else {
		$('#pikame').PikaChoose();
	}

	
}

var currentPicture = 1;
//SLIDESHOW FUNCTION
function rotatePics(currentPhoto) {
	
	var numberOfPhotos = $('.e-panel img').length;
	currentPhoto = currentPhoto % numberOfPhotos;

	$('.e-panel img').eq(currentPhoto).fadeOut(function() {
		
		//re-roder the z-index
		$('.e-panel img').each(function(i) {
			$(this).css(
				'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
			);
		});

		$(this).show();
		
		/* setTimeout(function() { rotatePics(++currentPhoto); }, 5000 ); */
		
		currentPicture = ++currentPhoto;
	});
}
//
function getNextImage(destinationPhoto) {

	alert(destinationPhoto + " " + currentPicture);
}

function clearHomeTab() {
	$('#home #nav-sub li a').removeClass('selected');
	$('.item-container').find('.att').hide();
	$('.item-container').find('.acc').hide();
	$('.item-container').find('.rest').hide();
	$('.item-container').find('.events').hide();
	$('.item-container').find('.blog').hide();
}

function setSlideShow(type)
{
	if (type=="entry")
	{
		/* thumb beaviour */
		$('.thmb-container ul li img').hover(function() {
			$(this).fadeTo(200,1);
		}, function () {
			$(this).fadeTo(200,0.5);
		})
		$('.thmb-container ul li img').fadeTo(100,0.5)
		
		$('.thmb-container ul li a').click(function() {
			getNextImage(currentPicture, $(this).attr('rel'));
		})
		
		
		/* ENTRY SLIDE SHOW THMB CONTROLS */
		var thumbHeight = 100;
		var visibleThumbs = 3;
		var totalThumbs = $('.thmb-container ul').children().size();
		var containerSize = (totalThumbs*thumbHeight)-(visibleThumbs*thumbHeight);
		
		$('#nav-up').click(function() {
		
			var tempStr = $('.thmb-container ul').css('top');
			var tempArr = tempStr.split('px');
			var tempNum = parseFloat(tempArr[0]);
			var fullHeight = -(containerSize);
			
			if (tempNum > fullHeight)
			{
				$('.thmb-container ul').animate({
					top: '-=' + visibleThumbs*thumbHeight,
					queue: false
				}, 1500)
			} else {
				$('.thmb-container ul').animate({
					top: '-=10px',
					queue: false
				}, 'fast')
				$('.thmb-container ul').animate({
					top: '+=10px',
					queue: false
				}, 'fast')
			}
		});
		
		$('#nav-down').click(function() {
			rotatePics(currentPicture);
			var tempStr = $('.thmb-container ul').css('top');
			var tempArr = tempStr.split('px');
			var tempNum = parseFloat(tempArr[0]);
			var fullHeight = -(containerSize);
			
			if (tempNum < 0)
			{
				$('.thmb-container ul').animate({
					top: '+=' + visibleThumbs*thumbHeight,
					queue: false
				}, 1500)
			} else {
				$('.thmb-container ul').animate({
					top: '+=10px',
					queue: false
				}, 'fast')
				$('.thmb-container ul').animate({
					top: '-=10px',
					queue: false
				}, 'fast')
			}
		});
	
	}
}

// clearing  inputs on focus
function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = ""; } }
//replace input value with default on blur
function doReset(theText) { if (theText.value == "") { theText.value = theText.defaultValue; } }


