$(document).ready(function() {		
	
	//Execute the slideShow, set 4 seconds for each images
	slideShow(6000);

});

function slideShow(speed) {


	//append or add the RESTAURANT image list for browsers with scripting	
	$('ul#restaurantsSlideshow') .append('<li><a href="http://www.atvdlstanley.com.au/stanley_restaurant.php"><img src="http://www.atvdlstanley.com.au/images/admin/restaurant_chocolate.jpg" width="745" height="250" alt="Decadent chocolate treats" title="Decedant chocolate treats" /></a></li><li><a href="http://www.atvdlstanley.com.au/stanley_restaurant.php"><img src="http://www.atvdlstanley.com.au/images/admin/restaurant_surfTurf.jpg" width="745" height="250" alt="Fresh local oysters and prime beef are one of the regions specialties" title="Fresh local oysters and prime beef are one of the regions specialties" /></a></li><li><a href="http://www.atvdlstanley.com.au/stanley_restaurant.php"><img src="http://www.atvdlstanley.com.au/images/admin/restaurantFruit.jpg" width="745" height="250" alt="The rich volcanic soil of Tasmania is ideally suited to a wide variety of cool climate wines and berries in the sumer season" title="The rich volcanic soil of Tasmania is ideally suited to a wide variety of cool climate wines and berries in the sumer season" /></a></li>');
	
	//append or add the RESTAURANT image list for browsers with scripting	
	$('ul#gettingHereSlideshow') .append('<li><a href="http://www.atvdlstanley.com.au/maps_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/gettingTWalk.jpg" width="745" height="250" alt="Beautiful unspoiled wilderness offers a unique trekking opportunities" title="Beautiful unspoiled wilderness offers a unique trekking opportunities" /></a></li><li><a href="http://www.atvdlstanley.com.au/maps_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/gettingTSunset.jpg" width="745" height="250" alt="Colourful fungi from the rainforest and the Stanley Nut at sunset" title="Colourful fungi from the rainforest and the Stanley Nut at sunset" /></a></li><li><a href="http://www.atvdlstanley.com.au/maps_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/gettingTArial.jpg" width="745" height="250" alt="The historic VDL building from the street and arial view" title="The historic VDL building from the street and arial view" /></a></li>');
	
	//append or add the MAIN IMAGE list for browsers with scripting	
	$('ul#mainSlideshow') .append('<li><a href="http://www.atvdlstanley.com.au/stanley_things_to_see_do.php"><img src="http://www.atvdlstanley.com.au/images/admin/Stanley_Ban.jpg" width="745" height="250" alt="The Stanley Nut and the historic Stanley fishing village" title="The Stanley Nut and the historic Stanley fishing village" /></a></li><li><a href="http://www.atvdlstanley.com.au/accommodation_vdl_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/VDL_lounge_Ban.jpg" width="745" height="250" alt="Each suite at VDL Stanley has a spacious living area" title="Each suite at VDL Stanley has a spacious living area" /></a></li><li><a href="http://www.atvdlstanley.com.au/stanley_things_to_see_do.php"><img src="http://www.atvdlstanley.com.au/images/admin/VDL_Stanley_Ban.jpg" width="745" height="250" alt="The historic VDL building in the shaddow of the Stanley Nut" title="The historic VDL building in the shaddow of the Stanley Nut" /></a></li><li><a href="http://www.atvdlstanley.com.au/stanley_things_to_see_do.php"><img src="http://www.atvdlstanley.com.au/images/admin/Edge_of_the_world_Ban.jpg" width="745" height="250" alt="The Edge of The World North West Tasmania" title="The Edge of The World North West Tasmania" /></a></li>');

//append or add the SUITES IMAGE list for browsers with scripting	
	$('ul#suitesSlideshow') .append('<li><a href="http://www.atvdlstanley.com.au/accommodation_vdl_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/VDL_Bathroom_Ban.jpg" width="745" height="250" alt="Take a long soak in the luxurious bathroom at VDL Stanley" title="Take a long soak in the luxurious bathroom at VDL stanley" /></a></li><li><a href="http://www.atvdlstanley.com.au/accommodation_vdl_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/VDL_lounge_Ban.jpg" width="745" height="250" alt="Each suite at VDL Stanley has a spacious living area" title="Each suite at VDL Stanley has a spacious living area" /></a></li><li><a href="http://www.atvdlstanley.com.au/accommodation_vdl_stanley.php"><img src="http://www.atvdlstanley.com.au/images/admin/VDL_lounge2_Ban.jpg" width="745" height="250" alt="Each suite at VDL Stanley has a spacious living area" title="Each suite at VDL Stanley has a spacious living area" /></a></li>');
	
	//append or add the THINGS TO DO IMAGE list for browsers with scripting	
	$('ul#toDoSlideshow') .append('<li><a href="http://www.atvdlstanley.com.au/stanley_things_to_see_do.php"><img src="http://www.atvdlstanley.com.au/images/admin/toDoTulip.jpg" width="745" height="250" alt="Stanley Nut chairlift and Wynyard Tulip farm" title="Stanley Nut chairlift and Wynyard Tulip farm" /></a></li><li><a href="http://www.atvdlstanley.com.au/stanley_things_to_see_do.php"><img src="http://www.atvdlstanley.com.au/images/admin/toDoTree.jpg" width="745" height="250" alt="Tasmania has pristine lakes and lush rainforest for you to enjoy" title="Tasmania has pristine lakes and lush rainforest for you to enjoy" /></a></li>');
	
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
		
	//Display the caption NOTE I changed this to 0 because I didn't want the caption to show it was 0.7
	$('#slideshow-caption').css({opacity: 0, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption').animate({bottom:-70}, 300, function () {
			//Display the content
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);				
			$('#slideshow-caption').animate({bottom:0}, 500);	
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}

//NEXT SET OF SCRIPT .................................................................................
//opacity:0,display:"block",marginTop:0
// Code for the MENU FADE UP COULD ALS BE USED FOR A POPUP 
$(document).ready(function(){
						   
  $("ul#subNav li").each(function(){
		var t;
		var isanimated = false;
		var isvisible = false;
		var popup = $("a",this);
		$(this).mouseover(function(){
			if (t) clearTimeout(t);
			if (!isvisible && !isanimated){
				isanimated = true;
				popup.css({opacity:0.3}).animate({opacity:0.9},300, function(){isanimated=false;isvisible=true;});
			} else {
				return;
			}
		}).mouseout(function(){
			if (t) clearTimeout(t);
			if (!isanimated && isvisible){
				t = setTimeout(function(){isanimated=true;popup.animate({opacity:0.9},0, function(){popup.css({opacity:0.7});isvisible=false;isanimated=false;});}, 0);
			} else {
				return;
			}
		});
	  });
  		//});
							 
  
//Code for the DROPDOWN MENU NOTE I have left it open for 5 seconds so that people can still navigate the remainder... before it closes up 
  $("ul#subNav li.dropDown").each(function(){
		var t;
		var isanimated = false;
		var isvisible = false;
		var popup = $("ul",this);
		$(this).mouseover(function(){
			if (t) clearTimeout(t);
			if (!isvisible && !isanimated){
				isanimated = true;
				//popup.slideDown(500).css({opacity:0.7, display:'block'}).animate({opacity:0.9, display:'block'},300, function(){isanimated=false;isvisible=true;});
				//SWITCH THE ABOVE LINE OF CODE WITH THE BELOW LINE TO CHANGE THE SUB MENU ITEMS TO A DROP DOWN VERSION
				popup.css({opacity:0.7, display:'block'}).animate({opacity:0.9, display:'block'},300, function(){isanimated=false;isvisible=true;});
			} else {
				return;
			}
		}).mouseout(function(){
			if (t) clearTimeout(t);
			if (!isanimated && isvisible){
				//t = setTimeout(function(){isanimated=true;popup.slideUp(500).animate({opacity:0.9},0, function(){popup.css({opacity:0.7, display:'none'});isvisible=false;isanimated=false;});}, 5000);
				//ALSO SWITCH THE ABOVE LINE FOR THE LINE BELOW TO ANNIMATE THE COLLAPS OF THE DROP DOWN MENU
				t = setTimeout(function(){isanimated=true;popup.animate({opacity:0.9},0, function(){popup.css({opacity:0.7, display:'block'});isvisible=false;isanimated=false;});},0);
			} else {
				return;
			}
		});
	});
});


// Code for the SHADDOW BOX.............................................
function setupDemos() {

    Shadowbox.setup("a.gallery", {
        gallery:        "gallery",
        continuous:     false,
        counterType:    "skip",
		counterLimit: 20
    });
	Shadowbox.setup("a.gallerytwo", {
        gallery:        "gallerytwo",
        continuous:     false,
        counterType:    "skip",
		counterLimit: 20
    });
	Shadowbox.setup("a.galleryHeading", {
		displayCounter: false
	});
	
		Shadowbox.setup("a.productRight", {
		displayCounter: false
	});
	
    Shadowbox.setup("a.swf-gallery", {
        gallery:    "swf",
        continuous: true
    });

    Shadowbox.setup('a[title="Sweetness"]', {
        width: 512,
        height: 322,
        flashVars: {
            id:         "v2155043",
            vid:        "2021599",
            autoPlay:   1
        },
        flashParams: {
            AllowScriptAccess: "always",
            allowFullScreen: "true"
        }
    });

    Shadowbox.setup('a[title="The Last Eggtion Hero"]', {
        height:     360,
        width:      640,
        flashVars:  {
            clip_id:    "1893986",
            autoplay:   "1"
        }
    });

    Shadowbox.setup('a[title="While My Ukulele Gently Weeps"]', {
        height:     327,
        width:      400,
        flashVars:  {
            docid:    "1352016870638076087",
            autoplay: "1"
        }
    });

    Shadowbox.setup('a[title="Altaic Warrior - Clipped"]', {
        handleOversize: "none"
    });

    Shadowbox.setup('a[title="Altaic Warrior - Draggable"]', {
        handleOversize: "drag"
    });
}


//BELOW IS THE SCRIPT FOR THE MAILCHIMP FORM ... ERROR FEEDBACK ETC
$(document).ready(function(){
						   
			var fnames = new Array();var ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';var err_style = '';
try{
    err_style = mc_custom_error_style;
} catch(e){
    err_style = 'margin: 1em 0 0 0; padding: 1em 0.5em 0.5em 0.5em; background: ERROR_BGCOLOR none repeat scroll 0% 0%; font-weight: bold; float: left; z-index: 1; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: ERROR_COLOR;';
}
var mce_jQuery = jQuery.noConflict();
mce_jQuery(document).ready( function($) {
  var options = { errorClass: 'mce_inline_error', errorElement: 'div', errorStyle: err_style, onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
  var mce_validator = mce_jQuery("#mc-embedded-subscribe-form").validate(options);
  options = { url: 'http://atvdlstanley.us2.list-manage.com/subscribe/post-json?u=ec35f11604b7f6519f92d29ee&id=3f77ab3d79&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                beforeSubmit: function(){
                    mce_jQuery('#mce_tmp_error_msg').remove();
                    mce_jQuery('.datefield','#mc_embed_signup').each(
                        function(){
                            var txt = 'filled';
                            var fields = new Array();
                            var i = 0;
                            mce_jQuery(':text', this).each(
                                function(){
                                    fields[i] = this;
                                    i++;
                                });
                            mce_jQuery(':hidden', this).each(
                                function(){
                                	if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                		this.value = '';
									} else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                		this.value = '';
									} else {
	                                    this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
	                                }
                                });
                        });
                    return mce_validator.form();
                }, 
                success: mce_success_cb
            };
  mce_jQuery('#mc-embedded-subscribe-form').ajaxForm(options);

});
function mce_success_cb(resp){
    mce_jQuery('#mce-success-response').hide();
    mce_jQuery('#mce-error-response').hide();
    if (resp.result=="success"){
        mce_jQuery('#mce-'+resp.result+'-response').show();
        mce_jQuery('#mce-'+resp.result+'-response').html(resp.msg);
        mce_jQuery('#mc-embedded-subscribe-form').each(function(){
            this.reset();
    	});
    } else {
        var index = -1;
        var msg;
        try {
            var parts = resp.msg.split(' - ',2);
            if (parts[1]==undefined){
                msg = resp.msg;
            } else {
                i = parseInt(parts[0]);
                if (i.toString() == parts[0]){
                    index = parts[0];
                    msg = parts[1];
                } else {
                    index = -1;
                    msg = resp.msg;
                }
            }
        } catch(e){
            index = -1;
            msg = resp.msg;
        }
        try{
            if (index== -1){
                mce_jQuery('#mce-'+resp.result+'-response').show();
                mce_jQuery('#mce-'+resp.result+'-response').html(msg);            
            } else {
                err_id = 'mce_tmp_error_msg';
                html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
                
                var input_id = '#mc_embed_signup';
                var f = mce_jQuery(input_id);
                if (ftypes[index]=='address'){
                    input_id = '#mce-'+fnames[index]+'-addr1';
                    f = mce_jQuery(input_id).parent().parent().get(0);
                } else if (ftypes[index]=='date'){
                    input_id = '#mce-'+fnames[index]+'-month';
                    f = mce_jQuery(input_id).parent().parent().get(0);
                } else {
                    input_id = '#mce-'+fnames[index];
                    f = mce_jQuery().parent(input_id).get(0);
                }
                if (f){
                    mce_jQuery(f).append(html);
                    mce_jQuery(input_id).focus();
                } else {
                    mce_jQuery('#mce-'+resp.result+'-response').show();
                    mce_jQuery('#mce-'+resp.result+'-response').html(msg);
                }
            }
        } catch(e){
            mce_jQuery('#mce-'+resp.result+'-response').show();
            mce_jQuery('#mce-'+resp.result+'-response').html(msg);
        }
	}
}
});
