/**
 * @author Raymond Manalo & Keith Mancuso
 * @date 5/10/2010
 * 
 * Functions the slideshow of the featured community stories on housingworks.org
 * 
 **/

var GLB = {
	timer:10000,
	texttimer:10000
}
var SLD = {
	
	init:function(){
		setInterval("SLD.slideSwitch()", GLB.timer );
		//setInterval('homePgSwitch()', GLB.texttimer);
	},
	
	slideSwitch:function(){
			//clear out the buttons
			$(".allButtons").css("opacity","0.0");
			
			//set the $active vars to find the DIV with the active class
			var $active = $('#mainImage DIV.active');
			var $active2 = $('#hero DIV.active');
			
			//if no DIV with the active css class then take the last DIV of the HTML
			if($active.length == 0 && $active2.length == 0){
				$active = $('#mainImage DIV:last');
				$active2 = $('#hero DIV:last');
			}
			
			//make next the first DIV of the HTML
		    var $next = $active.next().length ? $active.next() : $('#mainImage DIV:first');
			var $next2 = $active2.next().length ? $active2.next() : $('#hero DIV:first');
			
			//set the class to last-active
			$active.addClass('last-active');
			$active2.addClass('last-active');
			
			//animate the mainimage div
			$next.css({
				opacity: 0.0
			}).addClass('active').animate({
				opacity: 1.0
			}, 1000, function(){
				$active.removeClass('active last-active');
			});
		
			//animate the hero text div
			$next2.css({
				opacity: 0.0
			}).addClass('active').animate({
				opacity: 1.0
			}, 1000, function(){
				$active2.removeClass('active last-active');
			});
			
		    $next.addClass('active');
		    $next2.addClass('active');
		    $active.removeClass('active');
		    $active2.removeClass('active');
			
		
	},
	
	homePgInit:function(arrayObj){
			setInterval('SLD.homePgSwitch()', 5000);
	},
	
	/*homePgSwitch:function(arrayInd){
		$('#container').css({
			'background': 'url('+arrayInd+') no-repeat 0 0'
		})
		//.home #container {	background: url(../i/screen/fpo-home1.jpg) no-repeat 0 0 }
	},*/
	
	showImage:function(imgStr,xpos,ypos,lnk,call){
		//SLD.changeBackground(imgStr);
		SLD.changePostion(xpos,ypos);
		SLD.changeCallToAction(lnk,call);
	},
	
	changeBackground:function(img){
		$('#mainImage').css({
			'background': 'url('+img+') no-repeat 0 0',
			opacity: 0.0
		}).animate({opacity: 1}, 5000, function(){
			
		});
	},
	
	changePostion:function(xpos,ypos){
		$('#hero DIV').css({
			'left':xpos,
			'top':ypos
		})
	},
	
	changeCallToAction:function(lnk,call){
		var htmlStr = '<h2 class="pink-button"><a href="'+lnk+'">> '+call+'</a></h2><h2 class="green-button"><a href="/donate">> Donate to Housing Works</a></h2>'
		$('#hero DIV').html(htmlStr);
		/*var pinkBtnHTML = '<a href="'+lnk+'">> '+call+'</a>'
		console.log(lnk);
		console.log($('.pink-button a'));*/
	}
}

