/* start home.js */
$(function($) {
	var slide = $('.gradient .body ').SlideShow({slideItem:'.quote',speed:6000});
	slide.init();
	
	$('.thumbs_album').fancybox({autoDimensions: true, padding: 10, margin:0, autoScale:false, overlayOpacity:0.6,
		titleFormat	:function(title,currentArray,currentIndex){
						return "<strong>"+title+"</strong>";
		}
	});
	
	$('.thumbs a.thumb').click(function(e){
		e.preventDefault();
		$(this).parent().parent().find('.thumbs_album:first').click();
	})
});

$.fn.SlideShow = function(options){
		var t = this;		
		t.currentId=0;
		t.slideNum=0;
		t.timer = null;
		var DEFAULTS = {
			slideItem:'.slide_item',
			createButtons: true,
			buttons:'ol li a',
			clickButtonStop: true, // after user clicks a button, the slide will stop or not
			clickButtonShowNum:true,
			speed:3000,// 3 seconds
			hideSpeed:'slow',
			showSpeed:'slow'
		};
		
		t.options = jQuery.extend({}, DEFAULTS, options || {});
		t.slideNum = $(t).find(t.options.slideItem).length;		
		
		t.show = function(i){
			var left = 0 - i * $(t).find(t.options.slideItem+':first').outerWidth(true);
			$(t).animate({left:left},t.options.hideSpeed);
			
			$(t).parent().find(t.options.buttons).removeClass('selected');
			$(t).parent().find(t.options.buttons).eq(i).addClass('selected');
			t.currentId = i;
		};
		
		t.start = function()
		{
			t.timer = setInterval(function(){t.next()},t.options.speed);
		};		
		
		t.stop = function()
		{
			clearInterval(t.timer);
			t.timer = null;
		};
		
		t.next = function()
		{
			t.currentId++;
			if(t.currentId>=t.slideNum)
				t.currentId = 0;
			t.show(t.currentId);
		};
		t.createButtons = function(){
			var html = "<ol>";
			for(var i=0;i<t.slideNum;i++)
				html += '<li><a href="javascript:void(0)"'+(i==0?' class="selected"':'')+' >'+(t.options.clickButtonShowNum?(i+1):'')+'</a></li>';
			html += "</ol>";
			t.parent().append(html);
		};		
		
		t.init = function()
		{
			if(t.options.createButtons)
				t.createButtons();
			
			$(t).parent().find(t.options.buttons).each(function(i){
				$(this).click(function(){
					if(i!=t.currentId)
						t.show(i);
					if(t.options.clickButtonStop)
					{
						if(t.timer)
						{
							t.stop();
						}
						else
							t.start();
					}
				});
			});
			if(t.slideNum>1)
				t.start();
			t.show(0);
		};
		return this;
};

/* end home.js */

