/*
	Awesome Slider v1.0
	Copyright 2010, Bogdan Pop of WebRaptor (http://www.bogdanpop.info / http://www.webraptor.eu)
	
	Date: Apr 20 2010
 
	Awesome Slider is a jQuery powered script that can be used to create full html sliding content windows.

	AwesomeSlider arguments:

	htmlIdentifier: '#slider_demo' - html class. ID NOT recommended
	xmlSource: 'slider_demo.xml' - path to xml source file
	continuous: true - slider will loop automatically
	timer: 1000 - delay between slides. Only if continuous is true
	hasFading: true - enables or disables content fading
	hasHeightToggleing: true - enables or disables content height toggleing
	heightToggleing: 1000 - duration to toggle
	fading: 1000 - duration to fade
	
	IF YOU USE AWESOME SLIDER IN YOUR WEBSITE PLEASE PROVIDE A LINK TO EITHER Awesome Slider's URL : http://products.webraptor.eu/AwesomeSlider or http://www.webraptor.eu/
	THANK YOU!
	
*/

function AwesomeSlider(options)
{
	// setting defaults
	if(options.continuous==null) options.continuous = true;
	if(options.timer==null) options.timer = 5000;
	if(options.hasFading==null) options.timer = true;
	if(options.hasHeightToggleing==null) options.hasHeightToggleing = true;
	if( (options.heightToggleing==null) && (options.hasHeightToggleing!=false) ) options.heightToggleing = 1000;
	if(options.fading==null) options.fading = 1000;
	//if(options.timer>0) options.timer = options.timer + (options.heightToggleing+options.fading)*2;
	
	// settings Slide2Next settings
	if(options.hasFading==true)
	{
		var invisible = 0;
		var opaque = 1;
	}
	else
	{
		var invisible = 1;
		var opaque = 1;
		options.fading = 0;
	}
	if(options.hasHeightToggleing==false) options.heightToggleing = 0;
	
	function Slide2Next(count,content,items,slideID)
	{	
		
		if(slideID>0) count = slideID;
		else if(count<items) count++;
		else count = 1; // reached the last slide, get back to first

		$(options.htmlIdentifier+' .splash-content').animate({opacity:invisible},options.fading, function(){
			// animating
			$(options.htmlIdentifier+' .splash-content').animate({height:'toggle'},options.heightToggleing, function(){
				
				// faded out, changing content
				$(options.htmlIdentifier+ ' .splash-content').html(content[count]);
				
				// change style of controls
				$(options.htmlIdentifier+' .splash-controls a.selected').removeAttr("class");
				$(options.htmlIdentifier+' .splash-controls a[rel='+count+']').attr("class","selected");
				// fading back in
				$(options.htmlIdentifier+' .splash-content').animate({height: 'toggle'}, options.heightToggleing, function(){
					$(options.htmlIdentifier+' .splash-content').animate({opacity:opaque},options.fading);
				});
			});
		});
		
		return count;
	}
	
	// initialise slider variables
	var items = 0;
	var content = new Array();
	var control = '';
	var count = 1;
	
	$.get(options.xmlSource, function(data)
	{ // get contents from xml

		$(data).find('slide').each(function()
		{
			// populate array
			items++;
			var $slide = $(this); 
			content[items] = $slide.find('content').text();
			// create controls
			if(items==1) control = control + '<a href="#" class="selected" rel="'+items+'">'+items+'</a>';
			else control = control + '<a href="#" rel="'+items+'">'+items+'</a>';
		});
		
		$(options.htmlIdentifier+' .splash-content').html(content[count]);
	
		// add controls
		
		$(options.htmlIdentifier+' .splash-controls').html(control);
	});
	// finished getting data and initialising the slider
	
	// control is clicked
	$(options.htmlIdentifier+' .splash-controls a').live('click',function (){
		var slideID = $(this).attr('rel');
		count = Slide2Next(count,content,items,slideID);
		// reset sliding interval
		if (options.continuous == true)
		{
			clearInterval(slideInterval);
			slideInterval = setInterval(function() {count = Slide2Next(count,content,items)}, options.timer );
		}
		return false;
	});
	
	// set sliding interval
	if (options.continuous == true)
	{
		var slideInterval = setInterval(function() {count = Slide2Next(count,content,items)}, options.timer );
	}
}
