//Slide Box Homepage
var currentIndex = 0;
function rotated(){
	var container = jQuery('#bottom-box div.box_text');
	
	var numitem = container.length;
	var leftitem = 350;
	currentIndex +=1;
	
	if(currentIndex == numitem){
		
		
		for(j=currentIndex; j>=0; j--){
			jQuery(container[j]).attr("id", "");
			leftitem = 350*(j+1);
			jQuery(container[j]).animate({left: leftitem}, 400);
			if(leftitem == 350){
				jQuery(container[j]).attr("id", "current");
			}
		}
		currentIndex = 0;
	}
	else{
	
		jQuery(container).each(function(i){
			jQuery(this).attr("id","");
			leftitem = jQuery(this).css("left");
			leftitem = parseInt(leftitem);
			
			leftitem -= 350;
			
			jQuery(this).animate({left: leftitem}, 400);
			if(leftitem == 350){
				jQuery(this).attr("id", "current");
			}
			
		});
	}
	/*
	
	for(i=0; i<numitem; i++){
			//alert(i);
			
			leftitem -=260;
			jQuery(container[i]).animate({left: leftitem},400);
		}*/
	/*
	jQuery(container[currentIndex]).animate({left: -970},400, function(){
		jQuery(this).css({left: 970});
	});
	*/
	
	/*
	currentIndex +=1;
	if(currentIndex == numitem){
		currentIndex = 0;
	}
	jQuery(container[currentIndex]).animate({left: 0},400);
	*/
	
}
//End Slide Box Homepage

function displayMap( link ) {
	if(link.search('output=embed')==-1) {
		link=link.concat('&output=embed');
	}
	window.open(link,"Map","location=no,status=no,menubar=no,resizable=yes,width=435,height=360,toolbar=no"); 
}
/*******************LightBox Moving and Zoom*************************/
function loadImage() {
		
		$outer_container=jQuery(".mages-gallery-popup");
		$imagePan_panning=jQuery("#imagepan .panning");
		$imagePan=jQuery("#imagepan");
		$imagePan_container=jQuery("#imagepan .largeimage");

		$outer_container.css("top", (jQuery(window).height()-($outer_container.outerHeight()))/2);
		$imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
		containerWidth=$imagePan.width();
		containerHeight=$imagePan.height();
		totalContentW=$imagePan_panning.width();
		totalContentH=$imagePan_panning.height();
		$imagePan_container.css("width",totalContentW).css("height",totalContentH);
		
		$imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);

		jQuery('#zoomTarget').zoomable();
	}

function createPopup() {
	maskOverlay = jQuery("<div>").attr("class","maskimage");
	jQuery("body").append(maskOverlay);
	
	popupContainer = jQuery('.images-gallery-popup');	
	
	var imageWidth = 900;
	var imageHeight = 900; //jQuery(window).height();
	
	var windowWidth = jQuery(window).width();
	var documentHeight = jQuery(document).height();
	var windowHeight = jQuery(window).height();
	
	jQuery('.maskimage').css({'opacity':'0.5', 'display':'block', 'height':documentHeight, 'z-index': 10});
	jQuery(popupContainer).css({'left': (windowWidth - imageWidth)/2,'top': 0,'width': imageWidth,'height':imageHeight}).show();
	
	jQuery('#loadingpopupimage').css({'left': (windowWidth - 32)/2,'top': (windowHeight - 32)/2});
	
	loadImage();
	jQuery('.leftarrow, .rightarrow').css('top',((imageHeight/2)-51))
	jQuery('div.largeimage').css({left: '-11px', top: '220px'});
}
function loadImg(url, obj, loading, msg)
{	
	
	var windowWidth = jQuery(window).width();
	var windowHeight = jQuery(window).height();
	
	jQuery(loading).css({'display':'block','left': (windowWidth - 32)/2,'top': (windowHeight - 32)/2}).stop(true,true).animate({opacity:1},1000);			//display the loading in progress image	
	jQuery(obj).html("<img src='"+url+"' class=\"panning\" id=\"zoomTarget\" />").css({opacity: 0});				//throw in the image into the div block
	
	var tmp = jQuery(obj).children();											//gets the image obj we just thrown in
		tmp[0].onload = function(){												//when the image has complete loaded
			jQuery(obj).stop(true,true).animate({opacity:1},1000);								//display the image
			jQuery(loading).stop(true,true).animate({opacity:0},1000).css({"display":"none"});	//hide the loading in progress image			
			jQuery('.leftarrow, .rightarrow').css({"display":"block"}).stop(true,true).animate({opacity:1},1000);
			jQuery('.images-gallery-popup').show();
			jQuery('.maskimage').remove();
			createPopup();
		}
		tmp[0].onerror = function(){											//when the image fail to load for various reason
			jQuery(this).css({"display":"none"});											//we hide the image that fail
			jQuery(obj).html(jQuery(obj).html()+"<div>"+msg+"</div>").stop(true,true).animate({opacity:1},1000);	//provides a message to the user instead
			jQuery(loading).stop(true,true).animate({opacity:0},1000).css({"display":"none"});	//hide the loading in progress image
		}
}
var thumbIndex = 0;
var numberImage = 0;

var popupImagesGallery = {
		
		setupEvents : function() {
			this.setupEventForShowPopup();
			this.setupPreviousButton();
			this.setupNextButton();
			this.setupClosePopopEvent();
		},
		
		setupEventForShowPopup : function() {		
			jQuery('.image-container a').click(function(e){
				
				jQuery('.maskimage').remove();
				
				thumbIndex = jQuery('.image-container a').index(this);
				
				var ele = '.largeimage';
				var popupContainer = '.images-gallery-popup';
				var loadingpopupimage = '#loadingpopupimage';
				var image = jQuery(this).attr('href'); 					
				loadImg(image,ele, loadingpopupimage, 'error');
				
				e.preventDefault();
			});
		
		},
		setupPreviousButton : function() {
			jQuery('div.images-gallery-popup .leftarrow').click(function(){
				jQuery('.images-gallery-popup').hide();
				popupImagesGallery.movingImage(false);				
			});		
		},
		setupNextButton : function() {
			jQuery('div.images-gallery-popup .rightarrow').click(function(){
				jQuery('.images-gallery-popup').hide();
				popupImagesGallery.movingImage(true);				
				
			});		
		},
		movingImage : function(move) {
			imageCount = jQuery('.image-container img').length;			
			if(move) {
				thumbIndex = (thumbIndex+1)%imageCount;
				
			} else {
				thumbIndex = (imageCount + thumbIndex-1)%imageCount;
			}
			jQuery('.image-container img').each(function(index, item){			
				if(index == thumbIndex) {
					
					popupImagesGallery.displayImagePopup(jQuery(this).attr('src'));
				}
			});			
		},
		displayImagePopup : function(image) {
			
			var ele = '.largeimage';
			var popupContainer = '.images-gallery-popup';
			var loadingpopupimage = '#loadingpopupimage';
			
			loadImg(image,ele, loadingpopupimage, 'error');			
		},
		setupClosePopopEvent : function() {			
			jQuery('a.close, .maskimage').live('click',function(e){
				jQuery('.images-gallery-popup').hide();
				jQuery('.maskimage').remove();
				e.preventDefault();
			});	
		}
		
}
jQuery(window).resize(function() {
	$imagePan.unbind("mousemove");
	$imagePan_container.css("top",0).css("left",0);
	jQuery(window).load();
});
jQuery(document).ready(function() {
	
	if(jQuery('#bottom-box').length){
		var container = jQuery('#bottom-box div.box_text');
		var numitem = container.length;
		var leftitem = 0;
		for(i=0; i<numitem; i++){
			//alert(i);
			leftitem +=350;
			jQuery(container[i]).animate({left: leftitem},400);
		}
		$intervalid_banner = setInterval( "rotated()", 5100 );
	}
	
	
	if(jQuery('#pane3').length)
	{
		jQuery('#pane3').jScrollPane({showArrows:true});
	}
	//Map pane
	if(jQuery('#pane2').length)
	{
		jQuery('#pane2').jScrollPane({showArrows:true});
	}
	
	
	//Map content
		var prop=jQuery(".active").attr("id");
				if(prop=='north') {
					jQuery("#ausmap").css("background-position", "0px -366px");
				}
				else if(prop=='queens') {
					jQuery("#ausmap").css("background-position", "0px 0px");
				}
				else if(prop=='west') {
					jQuery("#ausmap").css("background-position", "0px -732px");
				}
				else if(prop=='south') {
					jQuery("#ausmap").css("background-position", "0px -1099px");
				}
				else if(prop=='wales') {
					jQuery("#ausmap").css("background-position", "0px -1465px");
				}
				else if(prop=='victoria') {
					jQuery("#ausmap").css("background-position", "0px -1830px");
				}
				else if(prop=='tasmania') {
					jQuery("#ausmap").css("background-position", "0px -2197px");
				}
				else if(prop=='si') {
					jQuery("#ausmap").css("background-position", "0px -2564px");
					
				}
				else if(prop=='ni') {
					jQuery("#ausmap").css("background-position", "0px -2932px");
				}
				else {
					jQuery("#ausmap").css("background-position", "0px -3288px");
				}
				
			

			jQuery("ul").mouseout( function() {
				var prop=jQuery(".active").attr("id");
				if(prop=='north') {
					jQuery("#ausmap").css("background-position", "0px -366px");
				}
				else if(prop=='queens') {
					jQuery("#ausmap").css("background-position", "0px 0px");
				}
				else if(prop=='west') {
					jQuery("#ausmap").css("background-position", "0px -732px");
				}
				else if(prop=='south') {
					jQuery("#ausmap").css("background-position", "0px -1099px");
				}
				else if(prop=='wales') {
					jQuery("#ausmap").css("background-position", "0px -1465px");
				}
				else if(prop=='victoria') {
					jQuery("#ausmap").css("background-position", "0px -1830px");
				}
				else if(prop=='tasmania') {
					jQuery("#ausmap").css("background-position", "0px -2197px");
				}
				else if(prop=='si') {
					jQuery("#ausmap").css("background-position", "0px -2564px");
					
				}
				else if(prop=='ni') {
					jQuery("#ausmap").css("background-position", "0px -2932px");
				}
				else {
					jQuery("#ausmap").css("background-position", "0px -3288px");
				}
				
			});
			
			jQuery("#north").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -366px");
			});
			jQuery("#queens").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px 0px");
			});
			jQuery("#west").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -732px");
			});
			jQuery("#south").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -1099px");
			});
			jQuery("#wales").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -1465px");
			});
			jQuery("#victoria").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -1830px");
			});
			jQuery("#tasmania").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -2197px");
			});
			jQuery("#si").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -2564px");
			});
			jQuery("#ni").mouseover( function() {
				jQuery("#ausmap").css("background-position", "0px -2932px");
			});
			//call popup lightbox
			popupImagesGallery.setupEvents();
});
