$(document).ready(
    function() {
	    var myHS = new HijackStudio();
    }
);

var HijackStudio = function ( )  
{
	this._init();
}

var o = HijackStudio;

o.prototype._init = function( )
{
	$('.myselectbox').selectbox();
	$(".feat-title").hide();
	$(".feat-content").hide();
	$(".feat").hide();

	$(".vignette").hover(
		function(){
	      $(this).stop().fadeTo("fast", 0.50);
//	      $(this).parent().parent().parent().fadeTo("fast", 0.50);
		},
		function(){
	      $(this).stop().fadeTo("fast", 1);
//	      $(this).parent().parent().parent().fadeTo("fast", 1);
		}
	);	
	this.currFeat = 0;
	if ($(".feat").size() > 0) {
		this.showFeat();		
	}
	
    $('a[href$=".jpg"], a[href$=".png"]').lightBox({
        imageLoading: "/studio/wp-content/themes/hijack/images/lightbox/lightbox-ico-loading.gif",
    	imageBtnClose: "/studio/wp-content/themes/hijack/images/lightbox/lightbox-btn-close.gif",
    	imageBtnPrev: "/studio/wp-content/themes/hijack/images/lightbox/lightbox-btn-prev.gif",
    	imageBtnNext: "/studio/wp-content/themes/hijack/images/lightbox/lightbox-btn-next.gif"
    });

}


o.prototype.showFeat = function() {
	var el = $(".feat").eq(this.currFeat);
	el.show();

	var title = $("#"+el.attr("id")+" > .feat-title").html();
	$("#feature_content > h3").html(title);
	var _self = this;
	this.arrImg = new Array();
	$("#"+el.attr("id")+" img").each(function(){
		_self.arrImg.push($(this).attr("src"));
	})	
	this.currImage = 0;
	this.showFeatImage();

	this.currFeat++;
	if(this.currFeat >= $(".feat").size()) {
		this.currFeat=0;
	}


}

o.prototype.showFeatImage = function() {
    var _self = this;
	var src = this.arrImg[this.currImage];

	this.currImage++;
	if(this.currImage >= this.arrImg.length) {
		setTimeout(function() { _self.showFeat(); }, 5000);
	}
    var img = new Image();
    img.onload = function() {
        $("#featImage").fadeOut("slow", function() {
            var img = $("<img>").attr("src", src);
            $("#featImage").html(img).fadeIn("slow", function(){
				if (_self.currImage < _self.arrImg.length) {
					setTimeout(function() { _self.showFeatImage(); }, 5000);
				}
			});
        });
    }
	img.src = src;
}