
$(document).ready(function(){

// sets the description to off
$('.tourdetailsbox').hide();
$('.flashcontainer_images').hide();
$('.tourthumbnail_image').animate({opacity: .75}, 300);
$('.imagedescription').hide();

var thumbtohighlight="#tourthumbnail_image" + 1
highlight_thumbnail(thumbtohighlight);
imagecounter(1, thumbtohighlight);

var show_start;
var show_initiation;
var my_carousel;

initiate_the_show();

//**** STRAT THE CAROSEL FOR THUMBNAILS
jQuery("#tourthumbnail_car").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null,
		buttonNextCallback:   mycarousel_buttonNextCallback,
        buttonPrevCallback:   mycarousel_buttonPrevCallback,
		itemLoadCallback: itemLoadCallback
});
//**** END THE CAROSEL FOR THUMBNAILS


//CONTROL PAGE THUMBNAILS ROLLOVER
$('.tourthumbnail_image').hover(

	function() {
	//var specialchecknumber = 
	$(this).css("border", "solid 1px #7e8180");
  		//ADD CLICK ACTION NOW
  		$(this).animate({
    	opacity: 1,
    	top: '0',
		width: '34',
		height: '34',
		left: '-2'
 	 	}, 100);
	}, 
	
	function() {
	if ($(this).hasClass('active')) { 
  	$(this).css("border", "solid 1px #7e8180");
	} else {
	$(this).css("border", "solid 1px #1c2630");
  	}
	
		$(this).animate({
    	opacity: .5,
    	top: '0',
		width: '30',
		height: '30',
		left: '0'
 	 	}, 100);
		
	}
	
);
//END CONTROL PAGE THUMBNAILS ROLLOVER


$(".player").click(
	function(){
		playerpause();
});


$(".viewdetails").toggle(

function(){

		showmydetailsID = "#" + $(this).attr('id');
		showmydetailsID=showmydetailsID.replace('#viewdetail', '');
		showdetails="#imagedescription_" + showmydetailsID;
		
		playerpausedetails();
		
		getdivheight=$(showdetails).height();
		getdivheight=getdivheight+30;
		divpos=0-getdivheight;
		
		$(showdetails).css({
		top: divpos
		});
		
		$(showdetails).fadeIn('slow');
		
		$(this).html('[ Hide details ]');
	
	},
	
	function(){
		
		$(this).html('[ Show details ]');
		
		showmydetailsID = "#" + $(this).attr('id');
		showmydetailsID=showmydetailsID.replace('#viewdetail', '');
		showdetails="#imagedescription_" + showmydetailsID;
		
		$(showdetails).fadeOut('slow');
		
		
		
	}
	
	
	
	
	
	);

}); 
//END DOCUMENT DEFAULT START


var imagecount=1;
var numboxes;
var player=1;


function itemLoadCallback(carousel, state) {
		
}; 
				
//carousel actions
function mycarousel_initCallback(carousel, myCarousel) {
	my_carousel = carousel;
	
	jQuery('.tourthumbnail_image').bind('click', function() {
		stop_slideshow();		
		thumbtohighlight = "#" + $(this).attr('id');
		imagecount = thumbtohighlight.replace('#tourthumbnail_image', '');
		navigate_Gallery();	
		return false;
    });
	
	jQuery('#tourthumbnail_next').bind('click', function() {
		stop_slideshow();		
		imagecount ++;
		thumbtohighlight = "#tourthumbnail_image" + imagecount;
		navigate_Gallery();	
        return false;
    });

    jQuery('#tourthumbnail_prev').bind('click', function() {
		stop_slideshow();		
		imagecount --;
		thumbtohighlight = "#tourthumbnail_image" + imagecount;	
		navigate_Gallery();		
        return false;
    });
};



function start_the_show()
{

var numboxes = $(".tourthumbnail").length;

	if(imagecount==numboxes)
	{
		imagecount = 1;
	}else{
		imagecount ++;
	}
	
	
	
	//PUT IN PLACE TO STOP THE GALLERY WORKING ON 1 IMAGE!
	if (numboxes==1) {
	stop_slideshow()
	} else {
	//PUT IN PLACE TO STOP THE GALLERY WORKING ON 1 IMAGE!
	if (player==1) {
	//stop_slideshow()
	//} else {
	thumbtohighlight = "#tourthumbnail_image" + imagecount;
	highlight_thumbnail(thumbtohighlight);
	imagecounter(imagecount, thumbtohighlight);	
	my_carousel.scroll(jQuery.jcarousel.intval(imagecount));
	
	}
	}
	
	
	
}

function initiate_the_show()
{
	show_start = setInterval(start_the_show, 6000);
}

function stop_slideshow()
{
	clearInterval(show_start);
	if(typeof(show_initiation)!="undefined")
	{
		clearTimeout(show_initiation);
	}
}


function navigate_Gallery()
{
	highlight_thumbnail(thumbtohighlight);
	imagecounter(imagecount, thumbtohighlight);	
	my_carousel.scroll(jQuery.jcarousel.intval(imagecount));
	show_initiation = setTimeout(initiate_the_show, 3000);
	//$('.imagedescription').hide();
	//$(".viewdetails").html("[ View Details ]")
}

function highlight_thumbnail(_thumb_highlight)
{
	$('.tourthumbnail_image').css("border", "solid 1px #1c2630");
	$('.tourthumbnail_image').removeClass('active');

	$(_thumb_highlight).css("border", "solid 1px #7e8180");
	$(_thumb_highlight).addClass('active');
}


function mycarousel_moveto(moveid, myCarousel) {
	// Simply add all items at once and set the size accordingly.
	 carousel = myCarousel;
	//$('#site_content_footer').html(moveid);
	carousel.scroll(jQuery.jcarousel.intval(moveid));
}


function mycarousel_buttonNextCallback(carousel, button, enabled, idx) {
	if (enabled == false)
       //$("#tourthumbnail_next").hide();
	   $(".homethumbnail_button_right").hide();
    else if (enabled == true)
        //$("#tourthumbnail_next").show();
		$(".homethumbnail_button_right").show();
};

function mycarousel_buttonPrevCallback(carousel, button, enabled, idx) {
	if (enabled == false)
	$(".tourthumbnail_button").hide();
       //$("#tourthumbnail_prev").hide();
    else if (enabled == true)
       // $("#tourthumbnail_prev").show();
		$(".tourthumbnail_button").show();
};
//end carousel actions


function imagecounter(mynumber, imagediv){
	//NOW SET UP THE TEXT DESCRIPTION ETC...
	$('.tourdetailsbox').hide();
	desctoload="#tourdetailsbox_" +imagecount
	$(desctoload).fadeIn();
	
	//CALL IMAGE LOADER
	loadmainimage(imagediv);
}


//THIS LOADS THE IMAGE
function loadmainimage(getdiv){

gettitle=getdiv
getdiv=getdiv +"_link"


//LOAD IMAGE
var image=null;
image = $(getdiv).attr('longdesc');

var imagetitle=null;
gettitle= gettitle.replace('#tourthumbnail_image', '');
displaytitle = "#imagetitle_" + gettitle
$('.imagelabel').hide();


//PRELOADER AND LOAD IMAGE
$.imgpreload(image,function(){

		//$('#mainimage_clone').remove();
		//$("#mainimageA").clone().attr('id','mainimage_clone').appendTo('#mainimageB');
		//WORKS $('.flashcontainer_images').hide();
		//WORKS $('.flashcontainer_images').html('<img src="' + image + '" id="newimage"/>');
		
		$('.flashcontainer_images').fadeOut('slow', function(){ $('.flashcontainer_images').html('<img src="' + image + '" id="newimage" height="100%"/>'); });
		
		
		//NOW RESIZE BASED ON SCREEN HEIGHT
        // Your other custom code
		$('.flashcontainer_images').fadeIn('slow');
		
		$('#imagelabel').html(imagetitle);
		$(displaytitle).fadeIn('slow');
				
				
});


$('.flashcontainer_images').fadeIn('slow');
}

//SLIDESHOW CONTROLLER

function playerpause(){
	
 if (player==1){
	$(".playericon").attr("src", "files/play.gif");
	player=0;
	stop_slideshow();
 } else {
	$(".playericon").attr("src", "files/pause.gif");
	player=1;
	//$(".viewdetails").html("[ View Details ]");
	//$('.imagedescription').fadeOut();
	
	clearInterval(show_start);
	if(typeof(show_initiation)!="undefined")
	{
		clearTimeout(show_initiation);
	}
	
	initiate_the_show();
 }
 
}


function playerpausedetails(){
	player=1;
	playerpause();
}

function playerplaydetails(){
	player=0;
	playerpause();
}




//END SLIDESHOW CONTROLLER
