var dailyPic = function(){
	var navContainer = $('#daily_pic_Nav');
	var cP = 0;
	var w = new Image();
	var timerID;

	w.src = '/gui_resources/images/1x1.gif';

	var rotate = function(d){
		var img = document.getElementById('main_photo_img');
		switch(d){
			case '>':{
				cP++;
				if(cP == aP.length){
					cP = 0;
				}
			} break;
			case '<':{
				cP--;
				if(cP < 0){
					cP = aP.length-1;
				}
			} break;
		}
		img.src = w.src;
		img.width = aP[cP][2];
		img.height = aP[cP][3];
		timerID = self.setTimeout(swap, 50);
	};

	var swap = function(){
		document.getElementById('main_photo_img').src = aP[cP][1];
		document.getElementById('main_photo_txt').innerHTML = aP[cP][4];
		clearTimeout(timerID);
	};

	var zoom = function(){
		var winURL = '/content/2/module/photos/photo_id/' + aP[cP][0] + '/format/html/';
		window.open(winURL, 'main_photo', 'status=0,toolbar=0,menubar=0,scrollbars=auto,resizable=1,width=640,height=500');
	};

	navContainer.find('a.prev').click(function(event){
		event.preventDefault();
		rotate('<');
	}).end()
	.find('a.zoom').click(function(event){
		event.preventDefault();
		zoom('>');
	}).end()
	.find('a.next').click(function(event){
		event.preventDefault();
		rotate('>');
	});	
};

var showCase = function()
{
	var rootElement = $('#showcase');
	var tabs = rootElement.find('ul.tabs li');
	var panels = rootElement.find('.panels');
	var active = null;

	tabs.each(function(){
		var li = $(this);
		var anchor = li.find('a');
		var rel = li.attr('rel');
		anchor.click(function(event){
			event.preventDefault();
			if (rel == active){
				return false;
			}
			li.addClass('active').siblings().removeClass('active');
			panels.find('ul[rel="'+rel+'"]').addClass('active').siblings().removeClass('active');
			active = rel;
		});
	});
	
};

$(document).ready(function(){
	showCase();
	dailyPic();
	$("#ticker").jStockTicker({
		interval: 30,
		speed: 1
	});

	var slide =	$('.hoverSlide span.txt');

	$('.hoverSlide span.icon').hover(function(){
		$(this)
		.find('img').animate({
	    opacity: '0'
	  }, 100, function(){
			$(this)
			.attr('src','/gui_resources/images/hover_slide_big.png')
			.animate({
		    opacity: '1'
		  }, 200);
		}).end()
		.animate({
	    height: '50',
			top: '-20'
	  }, 200);
		slide.animate({
	    left: '0'
	  }, 400);
	},function(){
		$(this)
		.find('img').animate({
	    opacity: '0'
	  }, 100, function(){
			$(this)
			.attr('src','/gui_resources/images/hover_slide.png')
			.animate({
		    opacity: '1'
		  }, 200);
		}).end()
		.animate({
	    height: '23',
			top: '0'
	  }, 200);
		slide.animate({
	    left: '280'
	  }, 400);
	});

});

