//avoid conflict with other script
	//$j=jQuery.noConflict();
	var shownImageHome = 0;
	var shownImageMerchant = 0;
	var shownImageHome2 = 0;
	var shownImageMerchant2 = 0;
	var shownImage = 0;
	var shownImage2 = 0;
	var totalImagesHome = 2;	// 4 since int starts at 0
	var totalImagesMerchant = 2;	// 4 since int starts at 0
	var totalImagesMerchant2 = 5;	// 4 since int starts at 0	
	var totalImages = 0;
	var moveVal = 190;
	var holdval;
	
	function ImageRotator(dir, srcdiv, mvOverride, objTotal) {
		// override the moveVal for the slide
		if (mvOverride != undefined) {
			moveVal = mvOverride;
		}
		
		if (objTotal == 'home') {
			totalImages = totalImagesHome;
			shownImage = shownImageHome;
		} else {
			totalImages = totalImagesMerchant;
			shownImage = shownImageMerchant;
		}
		
		//
		if (dir == "right") {
			//alert("right: "+shownImage);
			if (shownImage < totalImages) {
				$("#"+srcdiv).animate({"left": "-="+moveVal+"px"}, "slow");
				if (objTotal == 'home') {
					shownImageHome++;
				} else {
					shownImageMerchant++;
				}
			} else {
				if (objTotal == 'home') {
					holdval = moveVal*totalImagesHome;
					$("#"+srcdiv).animate({"left": "+="+holdval+"px"}, "slow");
					shownImageHome = 0;
				}
			}
		} else {
			if(shownImage > 0) {
				$("#"+srcdiv).animate({"left": "+="+moveVal+"px"}, "slow");
				if (objTotal == 'home') {
					shownImageHome--;
				} else {
					shownImageMerchant--;
				}
			} else {
				if (objTotal == 'home') {
					holdval = moveVal*totalImagesHome;
					$("#"+srcdiv).animate({"left": "-="+holdval+"px"}, "slow");
					shownImageHome = totalImagesHome;

				}
			}
		}		
	}
	function ImageRotator2(dir, srcdiv, mvOverride, objTotal) {
		// override the moveVal for the slide
		if (mvOverride != undefined) {
			moveVal = mvOverride;
		}

		if (objTotal == 'home') {
			totalImages = totalImagesHome2;
			shownImage2 = shownImageHome2;
		} else {
			totalImages = totalImagesMerchant2;
			shownImage2 = shownImageMerchant2;
		}

		//
		if (dir == "right") {
			//alert("right: "+shownImage);
			if (shownImage2 < totalImages) {
				$("#"+srcdiv).animate({"left": "-="+moveVal+"px"}, "slow");
				if (objTotal == 'home') {
					shownImageHome2++;
				} else {
					shownImageMerchant2++;
				}
			} else {
				/*if (objTotal == 'home') {
					holdval = moveVal*totalImagesHome2;
					$("#"+srcdiv).animate({"left": "+="+holdval+"px"}, "slow");
					shownImageHome = 0;
				}*/
			}
		} else {
			if(shownImage2 > 0) {
				$("#"+srcdiv).animate({"left": "+="+moveVal+"px"}, "slow");
				if (objTotal == 'home') {
					shownImageHome2--;
				} else {
					shownImageMerchant2--;
				}
			} else {
				/*if (objTotal == 'home') {
					holdval = moveVal*totalImagesHome2;
					$("#"+srcdiv).animate({"left": "-="+holdval+"px"}, "slow");
					shownImageHome = totalImagesHome2;
				}*/
			}
		}		
	}
	function JumpToHitArea(id) {
		if (id != undefined && id != '') {
			var hit = $("#"+id+"_hit").offset().top;
			window.scrollTo(0,(hit-155));
		}
	}
	
	function positionFooter(obj) {
		var h = $(window).height();
		//alert(h);

		obj.css({
			position: 'fixed',
			top: h-50
		});
	}
	
	function positionHeader(obj) {
		var h = $(window).height();
		//alert(obj.offset().top);
		/*
		obj.css({
			position: 'fixed',
			top: h-50
		});
		*/
	}
	
	function getQueryString(id) {
		var urlParams = {};
		(function () {
		    var e,
		        a = /\+/g,  // Regex for replacing addition symbol with a space
		        r = /([^&=]+)=?([^&]*)/g,
		        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
		        q = window.location.search.substring(1);

		    while (e = r.exec(q))
		       urlParams[d(e[1])] = d(e[2]);
		})();
		
		return urlParams[id];
	}
	
    function setMinHeightContent(obj) {
    	var h = $(window).height();
    	//alert((obj.height()-150)+"--"+h);
    	
    	if ((obj.height()-150) < h) {
    		//alert("resize me");
    		obj.css({
        		height:h+300 
        	});
    	}
    }
    
    $(document).ready(function($) {
    	
    	// hook resize 
    	$(window).resize(function () { positionFooter($('#floating-box-footer')); });

    // set the content box to a min height
    
	//this is the floating content
    var $boxbody = $('#body');
	var $floatingboxhead = $('#floating-box-header');
	var $floatingboxfoot = $('#floating-box-footer');
	
	//
	positionFooter($floatingboxfoot);
	//
	setMinHeightContent($boxbody);
	//
	positionHeader($floatingboxhead);
	//
	JumpToHitArea(getQueryString('j'));
	
	if($('#body').length > 0){
 
	  var bodyY = parseInt($('#body').offset().top);
	  var originalHeadX = $floatingboxhead.css('margin-left');
	  var originalFootX = $floatingboxfoot.css('margin-left');
 
	  $(window).scroll(function () { 
 
	   var scrollY = $(window).scrollTop();
	   var isHeadFixed = $floatingboxhead.css('position') == 'fixed';
	   var isFootFixed = $floatingboxfoot.css('position') == 'fixed';

	   // TODO: possible bug here if not footer is needed
	   if($floatingboxhead.length > 0 && $floatingboxfoot.length > 0){
 
	      //$floatingbox.html("srollY : " + scrollY + ", bodyY : " 
           //                         + bodyY + ", isfixed : " + isfixed);
 
	      if ( scrollY > bodyY && !isHeadFixed ) {
			$floatingboxhead.stop().css({
			  position: 'fixed',
			  top: 0
			});
		} else if ( scrollY < bodyY && isHeadFixed ) {
	 	  	$floatingboxhead.css({
		  		position: 'relative',
		  		left: 0,
		  		top: 0
			});
	     }

	      if ( scrollY > bodyY && !isFootFixed ) {
				$floatingboxfoot.stop().css({
				  position: 'fixed',
				  top: 200
				});
			} else if ( scrollY < bodyY && isfixed ) {
		 	  	$floatingboxfoot.css({
			  		position: 'relative',
			  		left: 0,
			  		top: 200
				});
		     }
			     		
	   }
       });
     }
  });
    
    

