/*******************************************************************************
	jQuery.jadrotate (alpha!)
	-------------------------
	
	This is a simple ad rotator that will rotate a set of images smoothly. Takes in an object as a parameter
	of options:
		* interval 
			-> The time interval between the rotation of the images, the minimum is 3secs or 3000ms.
			   Defaults to 3000.
		* rotation
			-> This options specifies if the widget will rotate or not. Values are either 'on' or 'off'.
			   Defaults to 'on'.
		* listContainer (new in 1.5)
			-> The selector used to find the list container(the parent of the 'listSelector' if you specified one).
			   Defaults to '#jadrotate-list'.	   
		* listSelector
			-> The selector used to find the list inside the #jadrotate-list container(not neccessarily li).
			   No longer constrained to list elements. Defaults to 'li'.
		* img
			-> The selector used to find the images to be rotated. Defaults to '.jadrotate-img'.	   
	This is still in testing...
	
	@example
		conforms to the following markup:
		
		<script>
			$(function () {
				$.jadrotate({
					interval : 3000,
					rotation : 'on',
					listSelector : 'div.jad-list',
					img : '.jadrotate-img2'
				});
			});
		</script>
		
		<div id="jadrotate-box2">
			<div>
				<ul id="list-con">
					<li class="jadrotate:activate(test-active) asdf asdff">advertisement 1</li>
					<li class="jadrotate:activate(test-active)">advertisement 2</li>
					<li class="asdf jadrotate:activate(test-active)  asdff">advertisement 3</li>
					<li class="jadrotate:activate(test-active)">advertisement 4</li>
					<li class="jadrotate:activate(test-active)">advertisement 5</li>
					<li class="asdf asdff jadrotate:activate(test-active)">advertisement 6</li>
				</ul>
			</div>
			<div style="float: right; padding-top: 20px;">
				<a href="#1"><img src="img/1.jpg" class="jadrotate-img2" alt="hellow from image 1" style="width: 500px; height: 400px;"/></a>
				<a href="#2"><img src="img/2.jpg" class="jadrotate-img2" alt="hellow from image 2" style="width: 500px; height: 400px;"/></a>
				<a href="#3"><img src="img/3.jpg" class="jadrotate-img2" alt="hellow from image 3" style="width: 500px; height: 400px;"/></a>
				<a href="#4"><img src="img/4.jpg" class="jadrotate-img2" alt="hellow from image 4" style="width: 500px; height: 400px;"/></a>
				<a href="#5"><img src="img/5.jpg" class="jadrotate-img2" alt="hellow from image 5" style="width: 500px; height: 400px;"/></a>
				<a href="#6"><img src="img/6.jpg" class="jadrotate-img2" alt="hellow from image 6" style="width: 500px; height: 400px;"/></a>
			</div>
		</div>
	
	Hooks for the markup: (depreciated!)
	-----------------------------------
		(If not using $.fn.jadrotate)
		-> #jadrotate-box
			|_ #jadrotate-list
			|_ .jadrotate-img 
			
		-> 	jadrotate:activate(<your-class-here>)
			 - The class that is activated when the list is hovered.
			 
		->  .jadrotate-active
			 - A class that is given by jadrotate to the list item which is active.
			 
	Tested on JSLint (http://jslint.com/) with no errors!		
			
	LM: 07-06-10

	@dependencies jquery 1.3.2 and above	
	@author Rafael Gandionco (http://elrafa.0fees.net) "Write Less, Destroy More"
	@version 1.5.1
	
********************************************************************************/
(function(g,r,b){b('<style type="text/css">.jadrotate-hide{display:none;}</style>').appendTo(r.getElementsByTagName("head")[0]);b.fn.jadrotate=function(m){if(this.length<=0)return this;var c,n;c=b.extend({},{interval:3E3,rotation:"on",listSelector:"li",listContainer:"#jadrotate-list",img:".jadrotate-img"},m);var d=0;return this.each(function(){var h=b(this),i=h.find(c.listContainer),f=h.find(c.img),e=i.find(c.listSelector),j=f.closest(":not(a)");h=g.parseFloat(h.jquery);f.addClass("jadrotate-hide");
var l,q,s=c.interval;if(c.interval)if(c.interval<3E3)c.interval=3E3;if(e.length!==f.length)throw"jadrotate:ERROR -> The number of list does not match the number of images to rotate!";if(i.length<=0)throw"jadrotate:ERROR -> "+c.listContainer+" can't be found!";if(f.length<=0)throw"jadrotate:ERROR -> .jadrotate-img is missing. Their are no images to rotate!";if(e.length<=0)throw"jadrotate:ERROR -> "+c.listSelector+" can't be found!";j.length>0&&j.css({position:"relative"});f.css({position:"absolute",
display:"none"});f.eq(0).css("display","block");e.each(function(){var a=b(this),k;if(b.trim(this.className)!==""){l=/jadrotate:activate\(.{1,}\)/.exec(this.className);if(l!==null){a.removeClass(l[0]);k=l[0].replace(/^.*jadrotate:activate\(/,"").replace(")","");a.data("jadrotate-active-class",k+" jadrotate-active")}else a.data("jadrotate-active-class","jadrotate-active")}else a.data("jadrotate-active-class","jadrotate-active")});var o=function(){e.each(function(){var a=b(this);a.removeClass(a.data("jadrotate-active-class"))})},
p=function(){if(b.trim(c.rotation).toLowerCase()==="on"){g.clearTimeout(n);f.eq(d).animate({opacity:1},500,function(){d++;if(d>e.length-1)d=0;else{o();e.eq(d).addClass(e.eq(d).data("jadrotate-active-class"))}var a=b(this);f.eq(d).hide().fadeIn("slow",function(){if(d===0){o();e.eq(d).addClass(e.eq(d).data("jadrotate-active-class"));a.fadeOut("slow")}else a.hide();n=g.setTimeout(p,c.interval)})})}};if(h<1.4){i="mouseover";j="mouseout"}else{i="mouseenter";j="mouseleave"}e.live(i,function(){b.trim(c.rotation).toLowerCase()===
"on"&&g.clearTimeout(n);g.clearTimeout(q);var a=b(this),k=e.index(this);f.hide().eq(k).show();d=k;o();a.addClass(a.data("jadrotate-active-class"))}).live(j,function(){var a=b(this);q=g.setTimeout(function(){a.removeClass(a.data("jadrotate-active-class"));p()},s)});(function(){e.eq(d).addClass(e.eq(d).data("jadrotate-active-class"));g.setTimeout(function(){p()},c.interval)})()})};b.jadrotate=function(m){return b("#jadrotate-box").jadrotate(m)}})(this,this.document,this.jQuery);
