/*
Version: 1.0
Author: Abraham beshara
Date: 2/10/2008
Description:
	This plugin is based on the property image scroll used on http://www.belleproperty.com.au/
	It organises subimages into a horizontal scroll and replaces main image with selected subimage.
*/

(function($){
$.fn.horz_scroll = function(options) {
	var defaults = {
		mainimage: 'mainimage', //ID of mainImage you wish to replace
		border: 'both', //Both or Single or none
		bordersize: '7' //Size of border in pixels
	};
	var options = $.extend(defaults, options);
  
	var wrapName = "#"+$(this).attr("id");
	var allimages = $(wrapName+" img");
	var ulWidth = allimages.length * $(wrapName+" img:first").attr("width");	
	var divWidth = parseFloat($(this).css('width'), 10)
	
	// Set UL Width
	switch(options.border){
		case 'both':
			var borderthickness = options.bordersize * 2;
			ulWidth = ulWidth + (allimages.length * borderthickness);
			break;
		case 'single':	
			ulWidth = ulWidth + (allimages.length * options.bordersize);
			break;
	}	
	
	$(wrapName+" ul").css("width", ulWidth);
	//End Set Width
	if (ulWidth > divWidth && document.all && $.browser.version < "8") $(this).css('padding-bottom', 18);//Adjust Height for scrollbar
	
  	//Changes main image on click
	$(wrapName +" a").click(function(){
		$("img#"+options.mainimage).attr("src", $(this).attr("href"));
      	return false;
	});
	
};
})(jQuery);
