﻿//Blog inline Slide Show class for MT
//Requires jQuery - developed using jquery-1.1.2.js

function blogSSClass() {
this.ss = new Object;
var sThis = this; //cached This for use in jQuery
//add the horz slide transition extension to jQuery
//this.left= function (oTarget, sId) {jQuery(oTarget).left(sThis,sId);};


//Find some slideshows, get some params
blogSSClass.prototype.loader = function () {

jQuery('.slideshow').each(function(sIndex){
	var sId='ss_'+sIndex;
		var jThis=jQuery(this);
	sThis.ss[sId] = new Object;
	sThis.ss[sId].slides = new Object;
	sThis.ss[sId].count = 0;
	sThis.ss[sId].curr = 0;
	sThis.ss[sId].sWidth = 0;
	sThis.ss[sId].pos = -1;

	//scan for slides as il's, discount nested li's
	//and only grab the ul's first-level children
	sThis.ss[sId].slides = jThis.children('li').not(jQuery(this).filter(function() {
		return jQuery(this).parents('li');
		}));
	//if there are no slides, clean up and move on to the next ul
	if (sThis.ss[sId].slides.length <=0) {delete this.ss[sId]; return false;}
	sThis.ss[sId].count = sThis.ss[sId].slides.length;	
	sThis.ss[sId].curr = 1;
	jThis.attr('id',sId);

});
	//after we're done scanning for slideshows, start making them pretty
    sThis.skin();

}

//Skin the image list with the nav controls,
//frame, and clean up the styles
blogSSClass.prototype.skin = function () {
	for (sId in sThis.ss){ 
		jThis=jQuery('#'+sId);
		jThis.wrap('<div id="'+sId+'f" class="ssFrame"></div>');
		frame = jThis.parent('div.ssFrame'); // save this for later please
    	sThis.ss[sId].sWidth = jQuery("div.ssFrame").width();//grabs the width from css
		jThis.find('img').removeAttr('style');
		//sThis.ss[sId].slides.each(function (){
			//jQuery(this).width(sThis.ss[sId].sWidth);//assigs width as inline style
		//	});
		jThis.find('span').each(function(){
		jQuery(this).before(jQuery(this).html());
		jQuery(this).remove();
		});
		
		var sNav = '<div class="ssControl"><div class="sPrev" title="Previous slide">Previous Slide</div><span> | </span><div class="sNext" title="Next slide">Next Slide</div></div>';
		jThis.width((frame.width() * (sThis.ss[sId].count+1)) + 'px');
		jThis.before('<div class="ssNav"><div class="count">slide <span id="'+sId+'c">1</span> of '+sThis.ss[sId].count+'</div>'+sNav+'</div>');
		//set the frame height to accomodate the first slide
		jThis.height(jQuery(sThis.ss[sId].slides[0]).height())
		sThis.bind(sId);
	}

}

//Bind the contol functions to their coresponding
//buttons
blogSSClass.prototype.bind=function (sIdl) {
jQuery('#'+sIdl+'f').find('.sNext').bind('click',function(){
if(sThis.ss[sIdl].curr < sThis.ss[sIdl].count) {
    sThis.ss[sIdl].pos-=sThis.ss[sIdl].sWidth;
    //jQuery('#'+sIdl+'f').height()
 	jQuery('#'+sIdl).animate({
	  left: sThis.ss[sIdl].pos
	  }, 'fast', function () {jQuery('#'+sIdl).animate({
	  height: jQuery(sThis.ss[sIdl].slides[sThis.ss[sIdl].curr]).height()
	  }, 'fast');
  	sThis.ss[sIdl].curr++;
  	    jQuery('#'+sIdl+'c').text(''+sThis.ss[sIdl].curr);} 
	); 

	  }
	  else{
	  sClone = jQuery(sThis.ss[sIdl].slides[0]).clone();
	  sClone.insertAfter(jQuery(sThis.ss[sIdl].slides[sThis.ss[sIdl].curr-1]));
//	  jQuery('#'+sIdl).css('left',-1);
 	jQuery('#'+sIdl).animate({
	  left: sThis.ss[sIdl].pos - sThis.ss[sIdl].sWidth
	  }, 'fast', function () {jQuery('#'+sIdl).css('left',0);
	  jQuery('#'+sIdl).animate({
	  height: jQuery(sThis.ss[sIdl].slides[0]).height()
	  }, 'fast');

        sThis.ss[sIdl].curr=1;
        sThis.ss[sIdl].pos=-1;
	    jQuery('#'+sIdl+'c').text(''+sThis.ss[sIdl].curr);
  	    sClone.remove();
  	    }
  	    ); 
	   			
	  }
	  
  	});
	
jQuery('#'+sIdl+'f').find('.sPrev').bind('click',function(){
if(sThis.ss[sIdl].curr > 1) {
    sThis.ss[sIdl].pos+=sThis.ss[sIdl].sWidth;
 	jQuery('#'+sIdl).animate({
	  left: sThis.ss[sIdl].pos
	  }, 'fast', function () {jQuery('#'+sIdl).animate({
	  height: jQuery(sThis.ss[sIdl].slides[sThis.ss[sIdl].curr-2]).height()
	  }, 'fast');
  	sThis.ss[sIdl].curr--;
  	    jQuery('#'+sIdl+'c').text(''+sThis.ss[sIdl].curr);} 
	); 
	  }
	  else{
	  sClone = jQuery(sThis.ss[sIdl].slides[0]).clone();
	  sClone.insertAfter(jQuery(sThis.ss[sIdl].slides[sThis.ss[sIdl].count-1]));
      jQuery('#'+sIdl).css('left',-((sThis.ss[sIdl].count*sThis.ss[sIdl].sWidth)+1));

//	  jQuery('#'+sIdl).css('left',-1);
 	jQuery('#'+sIdl).animate({
	  left: -(sThis.ss[sIdl].count-1)*sThis.ss[sIdl].sWidth
	  }, 'fast', function () {jQuery('#'+sIdl).animate({
	  height: jQuery(sThis.ss[sIdl].slides[sThis.ss[sIdl].count-1]).height()
	  }, 'fast');

        sThis.ss[sIdl].curr=sThis.ss[sIdl].count;
        sThis.ss[sIdl].pos=-(sThis.ss[sIdl].count-1)*sThis.ss[sIdl].sWidth;
	    jQuery('#'+sIdl+'c').text(''+sThis.ss[sIdl].curr);
        //jQuery('#'+sIdl).css('left',sThis.ss[sIdl].pos);
  	    sClone.remove();}
  	    ); 
	   			
	  }
  	});
}

}


ssController = new blogSSClass;

 jQuery(function() {
    ssController.loader();
 });


jQuery(document).ready(function() {
				
	jQuery("div.comments.archived h3").toggle(function(){
	   jQuery(this).next().show();
	   SI.ClearChildren.clear(); 
	   jQuery(this).addClass("expanded");
	   
	 },function(){
	   jQuery(this).next().hide("fast");
	   SI.ClearChildren.clear(); 
	   jQuery(this).removeClass("expanded");
	 });
	 
	 
});

