﻿function PhotoSlider(options) {
	this.thisInt = null;
	this.$crosslink = null;
	this.$navthumb = null;
	this.curclicked = 0;
	
	if(typeof options != 'undefined') {
		this.init(options);
	}
};


PhotoSlider.init = PhotoSlider.prototype.init = function(options) {
	this.$crosslink = $(options.crosslink);
	this.count = options.count;
	this.$tpanel = $(options.tpanel);
	
	var oThis = this;
	$(options.ppanel).find('img').width($(options.ppanel).width()).height($(options.ppanel).height());
	$(options.ppanel).codaSlider();
	
	
	this.$crosslink.click(function(){
		var $this = $(this);
		oThis.Intervalfn($this.attr('href').slice(1) - 1);
		return false;
	});
	
	this.Intervalfn();
};

PhotoSlider.Intervalfn = PhotoSlider.prototype.Intervalfn = function(cur) {
	clearInterval(this.thisInt);

	if(typeof cur != 'undefined')
		this.curclicked = cur;
	this.$crosslink.removeClass("active-link");
	
	this.$crosslink.eq(this.curclicked).addClass("active-link");
	$(".stripNav ul li a").eq(this.curclicked).trigger('click');
	this.$tpanel.find(".active-text").css({display:''}).removeClass("active-text");
	this.$tpanel.find("div").eq(this.curclicked).addClass("active-text").css({display:'block'});
	var oThis = this;
	this.thisInt = setInterval(function(){
		oThis.$crosslink.removeClass("active-link");
		oThis.$crosslink.eq(oThis.curclicked).addClass("active-link");
		$(".stripNav ul li a").eq(oThis.curclicked).trigger('click');
		oThis.$tpanel.find(".active-text").css({display:''}).removeClass("active-text");
		oThis.$tpanel.find("div").eq(oThis.curclicked).addClass("active-text").css({display:'block'});
	
		oThis.curclicked ++;
		if(oThis.count == oThis.curclicked) {
			oThis.curclicked = 0;
		}
	}, 3000);
};



$(function(){

	try{

		var o = new PhotoSlider();
		o.init({crosslink:'.cross-link', ppanel:'#photo-panel', tpanel:'#text-panel', count:5});
		
	} catch(e) {
		alert(e.description);
	}
	
});
