// JavaScript Document
var sSpeed=6000;
var sFadeSpeed=2000;
var sWidth=700; //this should be the same as .wSlide width
var sHeight=450; //this shoule be the same as .wSlide height
var wEngine;
var zi=500;
$(document).ready(function(){

	numOfSlides=$('.wSlide').length
	var curSlide=$('.wSlide:visible:first-child');
	$('#wSlide_wrap').css({'width':sWidth+'px','height':sHeight+'px'});
	$('#wSlide_wrap').wrapInner('<div id="wSlide_con" />');
	$('#wSlide_con').css({'width':sWidth+'px','height':sHeight+'px','position':'relative','overflow':'hidden'});
	
	slideNav='<div id="wSlide_nav" style="float:right; position:relative; top:' + (sHeight-40) + 'px;">';
	for(i=1;i<numOfSlides+1;i++){
		if($('.wSlide').eq(i-1).attr('title')==''){
			btntxt=i;
		}else{
			btntxt=$('.wSlide').eq(i-1).attr('title');
		}
		//attxt = 
		slideNav+='<div alt="'+ (i-1) +'" class="wSlide_btn" style="cursor:pointer;padding:4px;float:left;">'+btntxt+'</div>';
	}
	slideNav+='</div>';
	$('#wSlide_con').append(slideNav);
	$('#.wSlide_btn:first-child').addClass('wSlide_btn_active');
	$('#wSlide_nav').css("zIndex",zi+1);
	$('.wSlide').show('fast', function(){ //this restacks the slides so their in order from top to bottom
		$(this).css({'zIndex':zi});
		zi--;
	});
	
	$('.wSlide').css({'position':'absolute','top':0,'left':0}); //set position here in case no javascript
	
	$('.wSlide_btn').click(function(){
		clearInterval(wEngine);
		//alert($(this).html());
		$('.wSlide_btn').removeClass('wSlide_btn_active');
		$(this).addClass('wSlide_btn_active');
		slideNum=$(this).attr('alt');
		$('.wSlide').hide('fast',function(){
			if($(this).index()==numOfSlides-1){
				//alert("all animation complte");
				$('.wSlide').eq(slideNum).fadeIn(sFadeSpeed);
			}
		});
	});
	$.fn.startwSlide=function(){
		return setInterval(function(){
			curSlide.fadeOut(sFadeSpeed);
			$('.wSlide_btn').eq(curSlide.index()).removeClass('wSlide_btn_active');
			curSlide = curSlide.next(".wSlide");
			if(!curSlide.length){
				$('.wSlide').fadeIn(sFadeSpeed);
				curSlide=$('.wSlide:visible:first-child');
			}
			$('.wSlide_btn').eq(curSlide.index()).addClass('wSlide_btn_active');
		},sSpeed);
	}
	wEngine=$.fn.startwSlide();
});

