// JavaScript Document
var imageList = [
					 "images/gallery/gallery_image_01_sm.jpg",
					 "images/gallery/gallery_image_02_sm.jpg",
					 "images/gallery/gallery_image_03_sm.jpg",
					 "images/gallery/gallery_image_04_sm.jpg",
					 "images/gallery/gallery_image_05_sm.jpg",
					 "images/gallery/gallery_image_06_sm.jpg",
					 "images/gallery/gallery_image_07_sm.jpg",
					 "images/gallery/gallery_image_08_sm.jpg",
					 "images/gallery/gallery_image_09_sm.jpg",
					 "images/gallery/gallery_image_10_sm.jpg",
					 "images/gallery/gallery_image_11_sm.jpg",
					 "images/gallery/gallery_image_12_sm.jpg",
					 "images/gallery/gallery_image_13_sm.jpg",
					 "images/gallery/gallery_image_14_sm.jpg",
					 "images/gallery/gallery_image_15_sm.jpg",
					 "images/gallery/gallery_image_16_sm.jpg",
					 "images/gallery/gallery_image_17_sm.jpg",
					 "images/gallery/gallery_image_18_sm.jpg",
					 "images/gallery/gallery_image_19_sm.jpg",
					 "images/gallery/gallery_image_20_sm.jpg",
					 "images/gallery/gallery_image_21_sm.jpg",
					 "images/gallery/gallery_image_22_sm.jpg",
					 "images/gallery/gallery_image_23_sm.jpg",
					 "images/gallery/gallery_image_24_sm.jpg",
					 "images/gallery/gallery_image_25_sm.jpg",
					 "images/gallery/gallery_image_26_sm.jpg",
					 "images/gallery/gallery_image_27_sm.jpg",
					 "images/gallery/gallery_image_28_sm.jpg",
					 "images/gallery/gallery_image_29_sm.jpg",
					 "images/gallery/gallery_image_30_sm.jpg",
					 "images/gallery/gallery_image_31_sm.jpg",
					 "images/gallery/gallery_image_32_sm.jpg",
					 "images/gallery/gallery_image_33_sm.jpg",
					 "images/gallery/gallery_image_34_sm.jpg",
					 "images/gallery/gallery_image_35_sm.jpg",
					 "images/gallery/gallery_image_36_sm.jpg",
					 "images/gallery/gallery_image_37_sm.jpg",
					 "images/gallery/gallery_image_38_sm.jpg",
					 "images/gallery/gallery_image_39_sm.jpg",
					 "images/gallery/gallery_image_40_sm.jpg",
					 "images/gallery/gallery_image_41_sm.jpg",
					 "images/gallery/gallery_image_42_sm.jpg",
					 "images/gallery/gallery_image_43_sm.jpg",
					 "images/gallery/gallery_image_44_sm.jpg",
					 "images/gallery/gallery_image_45_sm.jpg",
					 "images/gallery/gallery_image_46_sm.jpg",
					 "images/gallery/gallery_image_47_sm.jpg"
					 
					 ];
	var urlList = [
					 "images/gallery/gallery_image_01.jpg",
					 "images/gallery/gallery_image_02.jpg",
					 "images/gallery/gallery_image_03.jpg",
					 "images/gallery/gallery_image_04.jpg",
					 "images/gallery/gallery_image_05.jpg",
					 "images/gallery/gallery_image_06.jpg",
					 "images/gallery/gallery_image_07.jpg",
					 "images/gallery/gallery_image_08.jpg",
					 "images/gallery/gallery_image_09.jpg",
					 "images/gallery/gallery_image_10.jpg",
					 "images/gallery/gallery_image_11.jpg",
					 "images/gallery/gallery_image_12.jpg",
					 "images/gallery/gallery_image_13.jpg",
					 "images/gallery/gallery_image_14.jpg",
					 "images/gallery/gallery_image_15.jpg",
					 "images/gallery/gallery_image_16.jpg",
					 "images/gallery/gallery_image_17.jpg",
					 "images/gallery/gallery_image_18.jpg",
					 "images/gallery/gallery_image_19.jpg",
					 "images/gallery/gallery_image_20.jpg",
					 "images/gallery/gallery_image_21.jpg",
					 "images/gallery/gallery_image_22.jpg",
					 "images/gallery/gallery_image_23.jpg",
					 "images/gallery/gallery_image_24.jpg",
					 "images/gallery/gallery_image_25.jpg",
					 "images/gallery/gallery_image_26.jpg",
					 "images/gallery/gallery_image_27.jpg",
					 "images/gallery/gallery_image_28.jpg",
					 "images/gallery/gallery_image_29.jpg",
					 "images/gallery/gallery_image_30.jpg",
					 "images/gallery/gallery_image_31.jpg",
					 "images/gallery/gallery_image_32.jpg",
					 "images/gallery/gallery_image_33.jpg",
					 "images/gallery/gallery_image_34.jpg",
					 "images/gallery/gallery_image_35.jpg",
					 "images/gallery/gallery_image_36.jpg",
					 "images/gallery/gallery_image_37.jpg",
					 "images/gallery/gallery_image_38.jpg",
					 "images/gallery/gallery_image_39.jpg",
					 "images/gallery/gallery_image_40.jpg",
					 "images/gallery/gallery_image_41.jpg",
					 "images/gallery/gallery_image_42.jpg",
					 "images/gallery/gallery_image_43.jpg",
					 "images/gallery/gallery_image_44.jpg",
					 "images/gallery/gallery_image_45.jpg",
					 "images/gallery/gallery_image_46.jpg",
					 "images/gallery/gallery_image_47.jpg"
					 
					 
					 ];
	
	var lastRan = -1;
	
	/**
	 * Since carousel.addItem uses an HTML string to create the interface
	 * for each carousel item, this method formats the HTML for an LI.
	 **/
	
	var fmtItem = function(imgUrl, url, title) {	
	 var clickevent= "onClick=\"check('"+imgUrl+"');\"";	 
		  var innerHTML = 
  '<a href="#" '+clickevent+'><img src="' +imgUrl +'" width="' +60 +'" height="' +60+'" />' + title +'<\/a>';	    
		return innerHTML;
		
	};
	
	/**
	 * Custom inital load handler. Called when the carousel loads the initial
	 * set of data items. Specified to the carousel as the configuration
	 * parameter: loadInitHandler
	 **/
	var loadInitialItems = function(type, args) {
		var start = args[0];
		var last = args[1]; 
		load(this, start, last);    
	};
	
	/**
	 * Custom load next handler. Called when the carousel loads the next
	 * set of data items. Specified to the carousel as the configuration
	 * parameter: loadNextHandler
	 **/
	var loadNextItems = function(type, args) {    
	
		var start = args[0];
		var last = args[1]; 
		var alreadyCached = args[2];
		//alert(last);
		if(last > 47)
		 {
			document.getElementById('ngimg').style.display='none'; 
		 }
		if(!alreadyCached) {
			load(this, start, last);
		}
	};
	
	/**
	 * Custom load previous handler. Called when the carousel loads the previous
	 * set of data items. Specified to the carousel as the configuration
	 * parameter: loadPrevHandler
	 **/
	var loadPrevItems = function(type, args) {
		var start = args[0];
		var last = args[1];
		//alert(last);
		var alreadyCached = args[2];
		if(last < 47)
		 {
			document.getElementById('ngimg').style.display=''; 
		 }
		
		if(!alreadyCached) {
			load(this, start, last);
		}
	};
	 
	 var load = function(carousel, start, last) {
		for(var i=0;i<47;i++) {
			var randomIndex = i;
			//alert(imageList[i]);
//			lastRan = randomIndex;
//			carousel.addItem(i, fmtItem(imageList[randomIndex], urlList[randomIndex], " "));
			//lastRan = randomIndex;
			try{
				carousel.addItem((i+1), fmtItem(imageList[i], urlList[i], " "));
			}
			catch(e){
				//alert(e.description);	
			}
	
	/*var load = function(carousel, start, last) {
		for(var i=start;i<=last;i++) {
			var randomIndex = getRandom(47, lastRan);
			lastRan = randomIndex;
			carousel.addItem(i, fmtItem(imageList[randomIndex], urlList[randomIndex], " "));*/
	/*
			// Example of an alternate way to add an item (passing an element instead of html string)
			var p = document.createElement("P");
			var t = document.createTextNode("Item"+i);
			p.appendChild(t);
			carousel.addItem(i, p );
	*/
		}
	};
	
	var getRandom = function(max, last) {
		var randomIndex;
		do {
			randomIndex = Math.floor(Math.random()*max);
		} while(randomIndex == last);
		
		return randomIndex;
	};
	
	/**
	 * Custom button state handler for enabling/disabling button state. 
	 * Called when the carousel has determined that the previous button
	 * state should be changed.
	 * Specified to the carousel as the configuration
	 * parameter: prevButtonStateHandler
	 **/
	var handlePrevButtonState = function(type, args) {
	
		var enabling = args[0];
		var leftImage = args[1];
		if(enabling) {
			leftImage.src = "images/previous.gif";    
		} else {
			leftImage.src = "images/seperator.gif";
		}
		
	};
	
	/**
	 * You must create the carousel after the page is loaded since it is
	 * dependent on an HTML element (in this case 'dhtml-carousel'.) See the
	 * HTML code below.
	 **/
	
	var carousel; // for ease of debugging; globals generally not a good idea
	var pageLoad = function() 
	{
		carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
			{
				numVisible:        4,
				animationSpeed:    0.25,
				scrollInc:         4,
				navMargin:         0,
				prevElement:       "prev-arrow",
				nextElement:       "next-arrow",
				loadInitHandler:   loadInitialItems,
				loadNextHandler:   loadNextItems,
				loadPrevHandler:   loadPrevItems,
				prevButtonStateHandler:   handlePrevButtonState
			}
		);
	};
	
	YAHOO.util.Event.addListener(window, 'load', pageLoad);
	
	featuredcontentglider.init({
			gliderid: "canadaprovinces", //ID of main glider container
			contentclass: "glidecontent", //Shared CSS class name of each glider content
			togglerid: "p-select", //ID of toggler container
			remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
			selected: 1, //Default selected content index (0=1st)
			persiststate: false, //Remember last content shown within browser session (true/false)?
			speed: 500, //Glide animation duration (in milliseconds)
			direction: "leftright", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
			autorotate: true, //Auto rotate contents (true/false)?
			autorotateconfig: [3000, 2] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
		})
	
	
  var ajax2 = new sack(); 
	function viewcheck()
	 {
	    stop_slide_show();
		ajax2.requestFile = 'ajaxjs/ajax.php?type=viewimage';
		ajax2.onCompletion = ViewImage;
		ajax2.runAJAX();
	 }
	function ViewImage()
	 {
		var content = ajax2.response;		
		document.getElementById("imggallery").innerHTML="";
		document.getElementById("imggallery").innerHTML=content;
	 }
	var ajax3 = new sack(); 
	
	function check(largeurl){	   
		stop_slide_show();
		ajax3.requestFile = 'ajaxjs/ajax.php?type=imagegallery&imgname='+largeurl;		
		ajax3.onCompletion = ImageGallery;
		ajax3.runAJAX();
	 }
    function ImageGallery()
	 {
		var content = ajax3.response;		
		document.getElementById("imggallery").innerHTML="";
		document.getElementById("imggallery").innerHTML=content;
	 }
	 
	
		function start_slide_show(){		    
			document.getElementById('default_glider_contentx').style.display='none';
			document.getElementById('default_glider_contenty').style.display='';
		}		
		function stop_slide_show(){
			document.getElementById('default_glider_contentx').style.display='';
			document.getElementById('default_glider_contenty').style.display='none';
		}
	function viewillustration()
	 {
	   location.href= 'argentina_galery.htm';
	 }