// JavaScript Document
var pause	= 0;
var slideViewer_Interval = 7000;

$(document).ready(function() {
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.65 }, 1 ); $("#navSource #navIndex li:first").addClass('active'); //runs function on click
	$("#navSource #navIndex li").click(function () {
										
	var imgSrc 		= $(this).find('.thumbInfo').attr("target");
	/* var imgTitle 		= $(this).find('.thumbInfo').attr("title");
	var imgDesc 		= $(this).find('.thumbInfo').attr("description");
	var _anchor 		= $(this).find('.thumbInfo').attr("anchor");
	var _anchorTitle 	= $(this).find('.thumbInfo').attr("anchorTitle");
	var timestamp		= $(this).find('.thumbInfo').attr("timestamp");
	var imgDescHeight 	= $(".main_image").find('.block').height();
	var imgAlt 		= $(this).find('img').attr("alt"); */
	
		
	if ($(this).is(".active")) {
		return false;
	} else {
		//onClick: take values from thumb, put on main!: main_title
		$(".main_image img").animate({ opacity: 0}, 250 );
		/* $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
			$(".main_image .block").animate({ opacity: 0.85, marginBottom: "0" }, 250 );
			/* $(".main_image .main_title").html(imgTitle);  */
			//$(".main_image .main_timestamp").html(timestamp);
			/* $(".main_image .main_anchor").html(_anchorTitle);
			$(".main_image .main_anchor").attr("href",_anchor); */
			/* $(".main_image .main_descr").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250 ); 
		}); */ 
		$(".main_image img").attr({ src: imgSrc /* , alt: imgAlt */}).animate({ opacity: 1}, 250 );
	}
	
	$("#navSource #navIndex li").removeClass('active');
	$(this).addClass('active');
	return false;$active = $(this);
	slideSwitchClick();
	})
	
	.hover(function(){
	$(this).addClass('hover');
		clearInterval(playSlideshow);
		playSlideshow = setInterval('slideSwitchTimed()', slideViewer_Interval );
		}, function() {
			$(this).removeClass('hover');
	});
	
	 //Toggle Teaser
	 $("a.collapse").click(function(){
	 $(".main_image .block").slideToggle();
	 $("a.collapse").toggleClass("show");
	 });
	
//runs function, set timer here
$(function() {
	playSlideshow = setInterval('slideSwitchTimed()', slideViewer_Interval );
});
});

function slideSwitchTimed() {
	if(pause ==0){
		$active = $('#navSource #navIndex li.active').next();
		if ( $active.length == 0 ) $active = $('#navSource #navIndex li:first');
		
		//alert('active: '+$active.find('.thumbInfo').attr("slideIndex"));	
		slideSwitch();
	}
}

function slideViewerTogglePlay(_pause){
	pause = _pause;
	if(pause == 1){
		$(".viewer_play").animate({ opacity: .8}, 250 );
		$(".viewer_pause").animate({ opacity: .25}, 250 );			
	}else{
		$(".viewer_pause").animate({ opacity: .25}, 250 );
		$(".viewer_play").animate({ opacity: .25}, 250 );			
	}
}
function slideSwitchClick() {
	slideSwitch();
}
	
function slideSwitch() {
	var $prev = $('#navSource #navIndex li.active');
	
	//Show active list-item		
	$prev.removeClass('active');
	$active.addClass('active');
	
	//Set Variables
	var imgSrc 		= $active.find('.thumbInfo').attr("target");
	/* var imgTitle 		= $active.find('.thumbInfo').attr("title");
	var imgDesc 		= $active.find('.thumbInfo').attr("description");
	var _anchor 		= $active.find('.thumbInfo').attr("anchor");
	var _anchorTitle 	= $active.find('.thumbInfo').attr("anchorTitle"); 
	var timestamp		= $active.find('.thumbInfo').attr("timestamp"); 
	var imgDescHeight 	= $(".main_image").find('.block').height();
	var imgAlt 		= $active.find('img').attr("alt"); */

	if ($(this).is(".active")) {
		return false;
	} else {		
		//onClick: take values from thumb, put on main!: main_title
		$(".main_image img").animate({ opacity: 0}, 250 );
		/* $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
			$(".main_image .block").animate({ opacity: 0.85, marginBottom: "0" }, 250 );
			/* $(".main_image .main_title").html(imgTitle);  */
			//$(".main_image .main_timestamp").html(timestamp);
			/* $(".main_image .main_anchor").html(_anchorTitle);
			$(".main_image .main_anchor").attr("href",_anchor); */
			/* $(".main_image .main_descr").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250 ); 
		}); */ 
		$(".main_image img").attr({ src: imgSrc /* , alt: imgAlt */}).animate({ opacity: 1}, 250 );
	}
	return false;
}
					    
/* var imgAlt 		= $(this).find('img').attr("alt");
var imgSrc 		= $(this).find('a').attr("href");
var imgDesc 		= $(this).find('.block').html();
var imgDescHeight 	= $(".main_image").find('.block').height(); */


/* var _title 	= $(this).find('.thumbInfo').attr("title");
var _descr 	= $(this).find('.thumbInfo').attr("description");
var _href 	= $(this).find('.thumbInfo').attr("href");
var _target 	= $(this).find('.thumbInfo').attr("target");
var _alt		= $(this).find('.thumbInfo').attr("alt");
alert(_title+': '+_descr+': '+_href+': '+_target+' :'+_alt); */

/* function fadeAllMyChildren() {
	alert($("#navIndex")childNodes.length);
	/* for(var j=0; j<cObj.childNodes.length; j++){
		alert(cObj.childNodes[j].innerHTML;);
		// Firefox puts in lots of #text nodes...skip these
		//if(cObj.childNodes[j].nodeName=='#text') continue;
		//cObj.childNodes[j].setAttribute('DragObj', cDrag);
	} */

//$(this).animate({ opacity: .8}, 250 );	

/* function fadeAllMyChildren(){
	alert($("#navIndex").childNodes.length);
} */