
// JQUERY
jQuery(document).ready(function() {
	
	// Load countdown
	if(document.getElementById('countDownDays')) {
		countDownTime();
	}
	
	
	
	
	
	// PHOTO GALLERY	
	if(document.getElementById('gallery1')) {
		
		function galleryCarousel_initCallbackControlls(carousel) {
			document['gallery_object_1'] = carousel;
			document['gallery_auto_1'] = true;
								
			jQuery('.gallery_thumbnails a.thumbnail').bind('click', function() {												
					document['gallery_auto_1'] = false;
					return false;
			});
			
			jQuery('.gallery .gallery_controlls .jcarousel-prev-horizontal').bind('click', function() {									
					document['gallery_auto_1'] = false;
					return false;
			});
			
			jQuery('.gallery .gallery_controlls .jcarousel-next-horizontal').bind('click', function() {											
					document['gallery_auto_1'] = false;
					return false;
			});
		}
		
		// Set
		jQuery('.gallery_thumbnails').jcarousel({
			scroll: 1, 
			animation: 'slow',
			start: 1,
			initCallback: galleryCarousel_initCallbackControlls
		});		
	
		// Thumbnails
		$('.gallery_thumbnails a.thumbnail').click(function(){
			var targetID = $(this).attr("id").replace("_thumb_", "_img_");	
			galleryLoadImage(targetID);					
		});
		
	}
	
	
}); 

// Gallery Load Image
function galleryLoadImage(targetId) {
	var attributes = targetId.split('_');
		
	if(document['gallery_'+attributes[0]]) {
		clearTimeout(document['gallery_'+attributes[0]]);
	}	
	if ($('#'+attributes[0]+' div.active').length > 0){
		$('#'+attributes[0]+' div.active').fadeOut('fast', function(){
			$('#'+targetId).fadeIn('fast').addClass('active');		
		}).removeClass('active');	
	} 			
	else{
		$('#'+id).fadeIn('fast').addClass('active');
	}
	
	if(document['gallery_auto_1']) {
		if(parseInt(attributes[2]) == 0) {
			document['gallery_object_1'].options.scroll = document['gallery_object_1'].options.size;
			document['gallery_object_1'].prev();
		} else if(parseInt(attributes[2]) > 4 && parseInt(attributes[2]) < document['gallery_object_1'].options.size) {
			document['gallery_object_1'].options.scroll = 1;
			document['gallery_object_1'].next();
		}
		
		if(document.getElementById(attributes[0]+"_img_"+(parseInt(attributes[2])+1))) {		
			document['gallery_'+attributes[0]] = setTimeout("galleryLoadImage('"+attributes[0]+"_img_"+(parseInt(attributes[2])+1)+"')",4000);					
		} else {
			document['gallery_'+attributes[0]] = setTimeout("galleryLoadImage('"+attributes[0]+"_img_0')",4000);
		}	
	}
	
}

