/*
*  Image settings are bottom of this page
*/



//full URL and dimensions of close, restore, and loading images
var fadeSlideShow_descpanel={
	controls: [['images/x.png',7,7], ['images/restore.png',10,11], ['images/loading.gif',54,55]], 
	
// Text settings start......
	fontStyle: 'normal 11px Verdana', //font style for text descriptions
	slidespeed: 200 //speed of description panel animation (in millisec)
}
// Text settings end......

//No need to edit beyond here...
jQuery.noConflict()

function fadeSlideShow(settingarg){
	this.setting=settingarg
	settingarg=null
	var setting=this.setting
	setting.fadeduration=setting.fadeduration? parseInt(setting.fadeduration) : 500
	setting.curimage=(setting.persist)? fadeSlideShow.routines.getCookie("gallery-"+setting.wrapperid) : 0
	setting.curimage=setting.curimage || 0 //account for curimage being null if cookie is empty
	setting.currentstep=0 //keep track of # of slides slideshow has gone through (applicable in displaymode='auto' only)
	setting.totalsteps=setting.imagearray.length*(setting.displaymode.cycles>0? setting.displaymode.cycles : Infinity) //Total steps limit (applicable in displaymode='auto' only w/ cycles>0)
	setting.fglayer=0, setting.bglayer=1 //index of active and background layer (switches after each change of slide)
	setting.oninit=setting.oninit || function(){}
	setting.onslide=setting.onslide || function(){}
	var preloadimages=[] //preload images
	setting.longestdesc="" //get longest description of all slides. If no desciptions defined, variable contains ""
	for (var i=0; i<setting.imagearray.length; i++){ //preload images
		preloadimages[i]=new Image()
		preloadimages[i].src=setting.imagearray[i][0]
		if (setting.imagearray[i][3] && setting.imagearray[i][3].length>setting.longestdesc.length)
			setting.longestdesc=setting.imagearray[i][3]
	}
	var closebutt=fadeSlideShow_descpanel.controls[0] //add close button to "desc" panel if descreveal="always"
	setting.closebutton=(setting.descreveal=="always")? '<img class="close" src="'+closebutt[0]+'" style="float:right;cursor:hand;cursor:pointer;width:'+closebutt[1]+'px;height:'+closebutt[2]+'px;margin:2px 0 140px 4px" title="Hide Description" />' : ''
	var slideshow=this
	jQuery(document).ready(function($){ //fire on DOM ready
		var setting=slideshow.setting
		var fullhtml=fadeSlideShow.routines.getFullHTML(setting.imagearray) //get full HTML of entire slideshow
		setting.$wrapperdiv=$('#'+setting.wrapperid).css({position:'relative', visibility:'visible', background:'white', overflow:'hidden', width:setting.dimensions[0], height:setting.dimensions[1]}).empty() //main slideshow DIV
		if (setting.$wrapperdiv.length==0){ //if no wrapper DIV found
			alert("Error: DIV with ID \""+setting.wrapperid+"\" not found on page.")
			return
		}
		setting.$gallerylayers=$('<div class="gallerylayer"></div><div class="gallerylayer"></div>') //two stacked DIVs to display the actual slide 
			.css({position:'absolute', left:0, top:0, width:'100%', height:'100%', background:'white'})
			.appendTo(setting.$wrapperdiv)
		var $loadingimg=$('<img src="'+fadeSlideShow_descpanel.controls[2][0]+'" style="position:absolute;width:'+fadeSlideShow_descpanel.controls[2][1]+';height:'+fadeSlideShow_descpanel.controls[2][2]+'" />')
			.css({left:setting.dimensions[0]/2-fadeSlideShow_descpanel.controls[2][1]/2, top:setting.dimensions[1]/2-fadeSlideShow_descpanel.controls[2][2]}) //center loading gif
			.appendTo(setting.$wrapperdiv)
		var $curimage=setting.$gallerylayers.html(fullhtml).find('img').hide().eq(setting.curimage) //prefill both layers with entire slideshow content, hide all images, and return current image
		if (setting.longestdesc!=""){ //if at least one slide contains a description (feature is enabled)
			fadeSlideShow.routines.adddescpanel($, setting)
			if (setting.descreveal=="always"){ //position desc panel so it's visible to begin with
				setting.$descpanel.css({top:setting.dimensions[1]-setting.panelheight})
				setting.$descinner.click(function(e){ //asign click behavior to "close" icon
					if (e.target.className=="close"){
						slideshow.showhidedescpanel('hide')
					}
				})
				setting.$restorebutton.click(function(e){ //asign click behavior to "restore" icon
					slideshow.showhidedescpanel('show')
					$(this).css({visibility:'hidden'})
				})
			}
			else{ //display desc panel on demand (mouseover)
				setting.$wrapperdiv.bind('mouseenter', function(){slideshow.showhidedescpanel('show')})
				setting.$wrapperdiv.bind('mouseleave', function(){slideshow.showhidedescpanel('hide')})
			}
		}
		setting.$wrapperdiv.bind('mouseenter', function(){setting.ismouseover=true}) //pause slideshow mouseover
		setting.$wrapperdiv.bind('mouseleave', function(){setting.ismouseover=false})
		if ($curimage.get(0).complete){ //accounf for IE not firing image.onload
			$loadingimg.hide()
			slideshow.paginateinit($)
			slideshow.showslide(setting.curimage)
		}
		else{ //initialize slideshow when first image has fully loaded
			$loadingimg.hide()
			slideshow.paginateinit($)
			$curimage.bind('load', function(){slideshow.showslide(setting.curimage)})
		}
		setting.oninit.call(slideshow) //trigger oninit() event
		$(window).bind('unload', function(){ //clean up and persist
			if (slideshow.setting.persist) //remember last shown image's index
				fadeSlideShow.routines.setCookie("gallery-"+setting.wrapperid, setting.curimage)
			jQuery.each(slideshow.setting, function(k){
				if (slideshow.setting[k] instanceof Array){
					for (var i=0; i<slideshow.setting[k].length; i++){
						if (slideshow.setting[k][i].tagName=="DIV") //catches 2 gallerylayer divs, gallerystatus div
							slideshow.setting[k][i].innerHTML=null
						slideshow.setting[k][i]=null
					}
				}
			})
			slideshow=slideshow.setting=null
		})
	})
}

fadeSlideShow.prototype={

	navigate:function(keyword){
		var setting=this.setting
		clearTimeout(setting.playtimer)
		if (setting.displaymode.type=="auto"){ //in auto mode
			setting.displaymode.type="manual" //switch to "manual" mode when nav buttons are clicked on
			setting.displaymode.wraparound=true //set wraparound option to true
		}
		if (!isNaN(parseInt(keyword))){ //go to specific slide?
			this.showslide(parseInt(keyword))
		}
		else if (/(prev)|(next)/i.test(keyword)){ //go back or forth inside slide?
			this.showslide(keyword.toLowerCase())
		}
	},

	showslide:function(keyword){
		var slideshow=this
		var setting=slideshow.setting
		if (setting.displaymode.type=="auto" && setting.ismouseover && setting.currentstep<=setting.totalsteps){ //if slideshow in autoplay mode and mouse is over it, pause it
			setting.playtimer=setTimeout(function(){slideshow.showslide('next')}, setting.displaymode.pause)
			return
		}
		var totalimages=setting.imagearray.length
		var imgindex=(keyword=="next")? (setting.curimage<totalimages-1? setting.curimage+1 : 0)
			: (keyword=="prev")? (setting.curimage>0? setting.curimage-1 : totalimages-1)
			: Math.min(keyword, totalimages-1)
		var $slideimage=setting.$gallerylayers.eq(setting.bglayer).find('img').hide().eq(imgindex).show() //hide all images except current one
		var imgdimensions=[$slideimage.width(), $slideimage.height()] //center align image
		$slideimage.css({marginLeft: (imgdimensions[0]>0 && imgdimensions[0]<setting.dimensions[0])? setting.dimensions[0]/2-imgdimensions[0]/2 : 0})
		$slideimage.css({marginTop: (imgdimensions[1]>0 && imgdimensions[1]<setting.dimensions[1])? setting.dimensions[1]/2-imgdimensions[1]/2 : 0})
		setting.$gallerylayers.eq(setting.bglayer).css({zIndex:1000, opacity:0}) //background layer becomes foreground
			.stop().css({opacity:0}).animate({opacity:1}, setting.fadeduration, function(){ //Callback function after fade animation is complete:
				clearTimeout(setting.playtimer)
				try{
					setting.onslide.call(slideshow, setting.$gallerylayers.eq(setting.fglayer).get(0), setting.curimage)
				}catch(e){
					alert("Fade In Slideshow error: An error has occured somwhere in your code attached to the \"onslide\" event: "+e)
				}
				setting.currentstep+=1
				if (setting.displaymode.type=="auto"){
					if (setting.currentstep<=setting.totalsteps || setting.displaymode.cycles==0)
						setting.playtimer=setTimeout(function(){slideshow.showslide('next')}, setting.displaymode.pause)
				}
			}) //end callback function
		setting.$gallerylayers.eq(setting.fglayer).css({zIndex:999}) //foreground layer becomes background
		setting.fglayer=setting.bglayer
		setting.bglayer=(setting.bglayer==0)? 1 : 0
		setting.curimage=imgindex
		if (setting.$descpanel)
			setting.$descpanel.css({visibility:(setting.imagearray[imgindex][3])? 'visible' : 'hidden'})
		if (setting.imagearray[imgindex][3])
			setting.$descinner.empty().html(setting.closebutton + setting.imagearray[imgindex][3])
		if (setting.displaymode.type=="manual" && !setting.displaymode.wraparound){
			this.paginatecontrol()
		}
		if (setting.$status) //if status container defined
			setting.$status.html(setting.curimage+1 + "/" + totalimages)
	},

	showhidedescpanel:function(state, showcontrol){
		var setting=this.setting
		var endpoint=(state=="show")? setting.dimensions[1]-setting.panelheight : this.setting.dimensions[1]
		setting.$descpanel.stop().animate({top:endpoint}, fadeSlideShow_descpanel.slidespeed, function(){
			if (setting.descreveal=="always" && state=="hide")
				setting.$restorebutton.css({visibility:'visible'}) //show restore button
		})
	},

	paginateinit:function($){
		var slideshow=this
		var setting=this.setting
		if (setting.togglerid){ //if toggler div defined
			setting.$togglerdiv=$("#"+setting.togglerid)
			setting.$prev=setting.$togglerdiv.find('.prev').data('action', 'prev')
			setting.$next=setting.$togglerdiv.find('.next').data('action', 'next')
			setting.$prev.add(setting.$next).click(function(e){ //assign click behavior to prev and next controls
				var $target=$(this)
				slideshow.navigate($target.data('action'))
				e.preventDefault()
			})
			setting.$status=setting.$togglerdiv.find('.status')
		}
	},

	paginatecontrol:function(){
		var setting=this.setting
			setting.$prev.css({opacity:(setting.curimage==0)? 0.4 : 1}).data('action', (setting.curimage==0)? 'none' : 'prev')
			setting.$next.css({opacity:(setting.curimage==setting.imagearray.length-1)? 0.4 : 1}).data('action', (setting.curimage==setting.imagearray.length-1)? 'none' : 'next')
			if (document.documentMode==8){ //in IE8 standards mode, apply opacity to inner image of link
				setting.$prev.find('img:eq(0)').css({opacity:(setting.curimage==0)? 0.4 : 1})
				setting.$next.find('img:eq(0)').css({opacity:(setting.curimage==setting.imagearray.length-1)? 0.4 : 1})
			}
	}

	
}

fadeSlideShow.routines={

	getSlideHTML:function(imgelement){
		var layerHTML=(imgelement[1])? '<a href="'+imgelement[1]+'" target="'+imgelement[2]+'">\n' : '' //hyperlink slide?
		layerHTML+='<img src="'+imgelement[0]+'" style="border-width:0; width:514px;" />\n'
		layerHTML+=(imgelement[1])? '</a>\n' : ''
		return layerHTML //return HTML for this layer
	},

	getFullHTML:function(imagearray){
		var preloadhtml=''
		for (var i=0; i<imagearray.length; i++)
			preloadhtml+=this.getSlideHTML(imagearray[i])
		return preloadhtml
	},

	adddescpanel:function($, setting){
		setting.$descpanel=$('<div class="fadeslidedescdiv"></div>')
			.css({position:'absolute', visibility:'hidden', width:'57%', left:230, top:setting.dimensions[1], font:fadeSlideShow_descpanel.fontStyle, zIndex:'1001'})
			.appendTo(setting.$wrapperdiv)
		$('<div class="descpanelbg"></div><div class="descpanelfg"></div>') //create inner nav panel DIVs
			.css({position:'absolute', left:0, top:0, width:setting.$descpanel.width()-8, padding:'8px'})
			.eq(0).css({background:'gray', opacity:0.1}).end()//"descpanelbg" div
			.eq(1).css({color:'brown'}).html(setting.closebutton + setting.longestdesc).end() //"descpanelfg" div
			.appendTo(setting.$descpanel)
		setting.$descinner=setting.$descpanel.find('div.descpanelfg')
		setting.panelheight=setting.$descinner.outerHeight()
		setting.$descpanel.css({height:setting.panelheight}).find('div').css({height:'100%'})
		if (setting.descreveal=="always"){ //create restore button
			setting.$restorebutton=$('<img class="restore" title="Restore Description" src="' + fadeSlideShow_descpanel.controls[1][0] +'" style="position:absolute;visibility:hidden;right:0;bottom:0;z-index:1002;width:'+fadeSlideShow_descpanel.controls[1][1]+'px;height:'+fadeSlideShow_descpanel.controls[1][2]+'px;cursor:pointer;cursor:hand" />')
				.appendTo(setting.$wrapperdiv)
		}
	},


	getCookie:function(Name){ 
		var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
		if (document.cookie.match(re)) //if cookie found
			return document.cookie.match(re)[0].split("=")[1] //return its value
		return null
	},

	setCookie:function(name, value){
		document.cookie = name+"=" + value + ";path=/"
	}
}

// Image settings start......

var mygallery3=new fadeSlideShow({
	wrapperid: "fadeshow3", //ID of blank DIV on page to house Slideshow
	dimensions: [518, 159], //width/height of gallery in pixels. Should reflect dimensions of largest image
	imagearray: [
		["images/aihs.jpg", "index.php?option=com_memberinstitute&id=13", "", "The Australian International Hotel School (AIHS) offers undergraduate programs in International Hotel Management and International Event<br>&nbsp;click on the image to view more..."],
		["images/asthm-perth.jpg", "index.php?option=com_memberinstitute&id=12", "", "The Australian School of Tourism and Hotel Management (ASTHM) established in 1989 and centrally located in Perth City alongside the leading<br>&nbsp;click on the image to view more..."],
		["images/blue-mtns.jpg", "index.php?option=com_memberinstitute&id=14", "", "The Blue Mountains International Hotel Management School, established since 1991, is a fully residential private multicultural college located on<br>&nbsp;click on the image to view more..."],
		["images/charles-darwin-university.jpg", "index.php?option=com_memberinstitute&id=4", "", "CDU is a young multi-sector institution, defined by creativity, flexibility and freedom from tradition. Its hub is in multi-cultural, tropical<br>&nbsp;click on the image to view more..."],
		["images/international-college-of-mgmt-syd.jpg", "index.php?option=com_memberinstitute&id=10", "", "International College of Management Sydney (ICMS) is a leading educator in business and professional management. Students at ICMS can specialise in<br>&nbsp;click on the image to view more..."],
		["images/southern-cross-university.jpg", "index.php?option=com_memberinstitute&id=5", "", "Close industry alignment and an entrepreneurial focus have established Southern Cross University(SCU) as one of Australia's most innovative and<br>&nbsp;click on the image to view more..."],
		["images/tafe-nsw-northern-sydney-institute.jpg", "index.php?option=com_memberinstitute&id=3", "", "Tourism, Hospitality and Events studies at TAFE NSW - Northern Sydney Institute (NSI) provide hands-on learning experiences within the bustling<br>&nbsp;click on the image to view more..."],
		["images/the-hotel-school-sydney.jpg", "index.php?option=com_memberinstitute&id=11", "", "The Hotel School Sydney is a unique industry-academic partnership between Southern Cross University and Mulpha Australia's hotel portfolio<br>&nbsp;click on the image to view more..."],
		["images/university-of-queensland.jpg", "index.php?option=com_memberinstitute&id=1", "", "University of Queensland (UQ) is listed among the top 50 learning and research institutions in the world. The University is a founding member<br>&nbsp;click on the image to view more..."],
		["images/victoria-university.jpg", "index.php?option=com_memberinstitute&id=6", "", "Set just 6km from the centre of cosmopolitan, multi-cultural Melbourne, Victoria University's School of Hospitality, Tourism and Marketing offers<br>&nbsp;click on the image to view more..."],
		["images/william-angliss-institute.jpg", "index.php?option=com_memberinstitute&id=9", "", "Since its establishment in 1940, William Angliss Institute has been dedicated to training and education opportunities for<br>&nbsp;click on the image to view more..."],
		["images/griffith-university.jpg", "index.php?option=com_memberinstitute&id=33", "", "Griffith University, established since 1975, is regarded as one of Australia's most innovative tertiary institutions and one of the most influential universities in the Asia-Pacific region.  GU is a large multi-campus institution with internationally recognised strengths in teaching and research.<br>&nbsp;click on the image to view more..."],
		["images/free-university.jpg", "index.php?option=com_memberinstitute&id=34", "", "The Free University of Bozen/Bolzano was founded on 31 October 1997 as a multilingual (Italian, German and English) internationally oriented institution. It promotes the free exchange of ideas and scientific knowledge, linking itself to the European humanities tradition and laying the foundations for its society by promoting respect for democratic principles.<br>&nbsp;click on the image to view more..."],
		["images/cornell-nanyang.jpg", "index.php?option=com_memberinstitute&id=29", "", "Cornell-Nanyang Institute of Hospitality Management is committed to develop leaders, managers and entrepreneurs for the Asian hospitality and tourism industry; build a world-class institution for the creation, translation and dissemination of knowledge to the hospitality and tourism industry in Asia and deliver high-quality hospitality education and research.<br>&nbsp;click on the image to view more..."],
		["images/htw-chur.jpg", "index.php?option=com_memberinstitute&id=27", "", "The University of Applied Sciences HTW Chur was founded in 1963. The University currently has 1,600 students studying in Bachelor and Mastersstudy programs. The HTW Chur is small in size and offers fine advantages with manageable class size, where students can contribute actively and learn efficiently.<br>&nbsp;click on the image to view more..."],
		["images/james-cook-university.jpg", "index.php?option=com_memberinstitute&id=32", "", "Since our establishment in 1970, James Cook University has expanded into a multi-campus institution with our largest campuses in Townsville and Cairns, smaller study centres in Mount Isa, Thursday Island, and Mackay, and campuses in Singapore and Brisbane.<br>&nbsp;click on the image to view more..."],
		["images/mci.jpg", "index.php?option=com_memberinstitute&id=31", "", "MCI Management Center Innsbruck, The Entrepreneurial SchoolŪ is an integral part of the unique Open University Innsbruck concept in Austria. With a strong focus on quality and customer orientation, MCI has moved up to join the leaders committed to offer its students high-grade study programs and attractive university services.<br>&nbsp;click on the image to view more..."],
		["images/FH-KREMS.jpg", "index.php?option=com_memberinstitute&id=30", "", "IMC University of Applied Sciences Krems is an international focused university located in the heart of the Wachau region in Austria. Since 1994 the IMC University of Applied Sciences Krems has taken on a pioneering role in the development of innovative solutions and practice-oriented degree programs.<br>&nbsp;click on the image to view more..."],
		["images/william-blue-college-of-hospitality-tourism.jpg", "index.php?option=com_memberinstitute&id=20", "", "William Blue has been attracting more than 500 of the best applicants from Australia and abroad on an annual<br>&nbsp;click on the image to view more..."] //<--no trailing comma after very last image element!
	],
	displaymode: {type:'auto', pause:4000, cycles:0, wraparound:false},
	persist: false, //remember last viewed slide and recall within same session?
	fadeduration: 500, //transition duration (milliseconds)
	descreveal: "always",
	togglerid: ""
})

// Image settings end......
