/* Javascript for StoryGarden Theme */

// Side bar lists

var sb_lists = new function() {
	this.btns = new Array();
	this.lists = new Array();
	this.lstLists = new Array('recentposts','cats','tags','archive');
	this.current = '';
	this.init = function() {
		var i;
		if (jQuery('#sb-btn-'+this.lstLists[0]).length<=0) return false;
		for (i=0;i<this.lstLists.length;i++) {
			this.btns[this.lstLists[i]]=jQuery('#sb-btn-'+this.lstLists[i]);
			this.btns[this.lstLists[i]].removeClass('selected');
			this.lists[this.lstLists[i]]=jQuery('#sb-list-'+this.lstLists[i]);
			this.lists[this.lstLists[i]].hide();
		};
		jQuery(".grptitles a.btn").click(function(){
			sb_lists.select(this.id.substring(7));
			return false;
		});
		return true;
	};
	this.select = function(name) {
		var found = false;
		for (var i=0;i<this.lstLists.length;i++) {
			if (this.lstLists[i] == name) {
				found = true;
				break;
			}
		}
		if (!found) return false;
		if (this.current != '') {
			this.lists[this.current].removeClass('show');
			this.btns[this.current].removeClass('selected');
		}
		this.btns[name].addClass('selected');
		this.lists[name].addClass('show');
		if (this.current !='') this.lists[this.current].fadeOut();
		this.lists[name].fadeIn();
		this.current = name;
		return true;		
	};
	
};

var home_top_slide = new function() {
	this.num = 0;
	this.current = 0;
	this.init = function() {
		var i=0;
		this.pic_lis = jQuery("#slider1 .pic-wnd li");
		this.num = this.pic_lis.length;
		if (this.num <= 0) return false;
		this.btn_as = jQuery("#slider1 .btn-wnd li a");
		if (this.btn_as.length != this.num) return false;
		this.pic_wnd = jQuery("#slider1 .pic-wnd");
		this.p_offset = this.pic_wnd.get(0).offsetLeft;
		
		for (i=0;i<this.num;i++) {
			this.pic_lis.get(i).rel = i;
			this.btn_as.get(i).rel = i;
		}
		
		this.btn_as.click(function(){
			home_top_slide.select(this.rel);
			return false;
		});
		return true;
	}
	this.select = function(which) {
		jQuery(this.btn_as.get(this.current)).removeClass('selected');
		jQuery(this.btn_as.get(which)).addClass('selected');
		var new_left = -1 * (this.pic_lis.get(which).offsetLeft - this.p_offset)
		this.pic_wnd.animate({left: new_left + "px"},400,"swing");
		this.current = which;
	}
};

var home_landscape = new function(){
	this.num = 0;
	this.current = 0;
	this.interval_time = 2000;
	this.init = function() {
		var i=0;
		if (jQuery('#landscape').length <= 0) return false;
		this.pics = jQuery("#landscape .pic li");
		this.num = this.pics.length;
		if (this.num <=0) return false;
		this.btns = jQuery("#landscape .btn li a");
		if (this.btns.length != this.num) return false;
		for (i=0;i<this.num;i++) {
			this.pics.get(i).rel = i;
			jQuery(this.pics.get(i)).removeClass('show').hide();
			this.btns.get(i).rel = i;
			jQuery(this.btns.get(i)).removeClass('selected');
		}
		
		this.btns.click(function(){
			home_landscape.select(this.rel);
			return false;
		});
		
		return true;
	};
	this.select = function(which) {
		jQuery(this.pics.get(this.current)).removeClass('show').fadeOut();
		jQuery(this.pics.get(which)).addClass('show').fadeIn();
		jQuery(this.btns.get(this.current)).removeClass('selected');
		jQuery(this.btns.get(which)).addClass('selected');
		this.current = parseInt(which);
		this.nextone = this.current+1;
		if (this.nextone == this.num) this.nextone = 0;
		//this.timeo = setTimeout(this.select(next),this.interval_time);
	};
	this.next = function(){
		this.select(this.nextone);
	};
};

///
jQuery(document).ready(function(){
	if (sb_lists.init()) {
		sb_lists.select('recentposts');
	}
	
	if (home_top_slide.init()) {
	}
	
	if (home_landscape.init()) {
		home_landscape.select(0);
		setInterval("home_landscape.next()",5000);
	}
});

