function tooltipElement(type,url,id,w,h){
	switch(type){
		case 'img' : 
			var newImg = 'image_' + id;
			if($('#' + newImg).length == 0){
				var newImageObject = '<img src="' + url + '" class="active" />';
				$('body').after('<div id="' + newImg + '" class="tooltip_image">' + newImageObject + '</div>');
				$("#" + newImg).fadeIn(200);
				
				$('#' + id ).mouseover(function(){
					$("#" + newImg).fadeIn(200);
				});
				
				$('#' + id ).mousemove(function(e){					
					$("#" + newImg).css({
						top: (e.pageY) + 10 + "px",
						left: (e.pageX) + 10 +  "px"
					});					
				});
				$('#' + id ).mouseout(function(e){
					$("#" + newImg).remove();
					
					
					/*$('#' + newImg).queue(function(){
						$(this).hide();
						$(this).dequeue();
					});*/
				});
			}

		break;
		case 'swf' :
			var newFlash = 'flash_' + id;
			if($('#' + newFlash).length == 0){		
				$('body').after('<div id="' + newFlash + '" class="tooltip_image"></div>');
				$('#' + newFlash).css('height', h);
				$('#' + newFlash).css('width', w);
				$('#' + newFlash).flash({swf:url,height:h, width:w});
			

				$('#' + id ).mousemove(function(e){
					$("#" + newFlash).fadeIn(200);
					$("#" + newFlash).flash().show();
					
					$("#" + newFlash).css({
						top: (e.pageY) + 10 + "px",
						left: (e.pageX) + 10 +  "px"
					});					
				});
				$('#' + id ).mouseout(function(e){
					$('#' + newFlash).fadeOut(200);
					$('#' + newFlash).queue(function(){
						//$(this).flash().remove();
						$(this).hide();
						$(this).dequeue();
					});
				});
			}
		break;
	}
}
var timers = new Array();
function swapImages(id,srcs){
	var newRotator = 'swapImages_' + id;
	if($('#' + newRotator).length == 0){			
		$('body').after('<div id="' + newRotator + '" class="tooltip_image"></div>');
		var c=0;
		for(num in srcs){
			var img = '<img src="' + srcs[num] + '" ';
			if(c==0) img += 'class="active"';
			img += ' />'
			c++;
			$('#' + newRotator).append(img);
		}	
		$('#' + newRotator).hide();
		clearInterval(timers[newRotator]);
		timers[newRotator] = setInterval('rotateImage("' + newRotator + '")', 3000);
		$('#' + newRotator).queue(function(){
			$("#" + newRotator).fadeIn(200);
			$(this).dequeue();
		});	

		$('#' + id ).mousemove(function(e){		
			$("#" + newRotator).css({
				top: (e.pageY) + 10 + "px",
				left: (e.pageX) + 10 +  "px"
			});
		});
		$('#' + id ).mouseover(function(){
			$("#" + newRotator).fadeIn(200);
			clearInterval(timers[newRotator]);
			timers[newRotator] = setInterval('rotateImage("' + newRotator + '")', 3000);
		});	
		$('#' + id ).mouseout(function(e){
			clearInterval(timers[newRotator]);
			$('#' + newRotator).fadeOut(200);
			$('#' + newRotator).queue(function(){
				//$(this).flash().remove();
				$(this).remove();
				$(this).dequeue();
			});	
			
		});	
	}
}

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
$(function () {	
	$('.dropdown a').hover(function () {
		$(this).stop(true).animate({paddingLeft: '40px'}, {speed: 100, easing: 'easeOutBack'});
	}, function () {
		$(this).stop(true).animate({paddingLeft: '20px'}, {speed: 100, easing: 'easeOutBounce'});
	});
});

function rotateImage(newRotator, direction){
	if( $('#' + newRotator ).css('display') == 'none' ){
		clearInterval(timers[newRotator]);
	}else{
		var $active = $( '#' + newRotator + ' .active');	
		var reset = true;
		
		if(typeof(direction)=='undefined'){ direction = 'next'; reset=false }
		switch(direction){
			case 'next':
				if(reset){ clearInterval(timers[newRotator]); timers[newRotator] = setInterval('rotateImage("' + newRotator + '")', 4000); }
				var $obj = ($active.next('img').length > 0) ? $active.next('img') : $( '#' + newRotator + ' img:first');
			break;
			case 'prev':		
				if(reset){ clearInterval(timers[newRotator]);  timers[newRotator] = setInterval('rotateImage("' + newRotator + '")', 4000); }
				var $obj = ($active.prev('img').length > 0) ? $active.prev('img') : $( '#' + newRotator + ' img:last')
			break;
		}
		if($obj && $($obj).hasClass('loaded')){
			var hasTitle = false;
			var $bottomText = $('#' + newRotator + ' .imageRotator_bottomText');
			var $background = $( '#' + newRotator + ' .imageRotator_background');
			
			if($obj.attr('title')!="") { 
				$bottomText.html($obj.attr('title')); 
				hasTitle = true;
				if($bottomText.css('display') != 'block') $bottomText.fadeIn();
			} else {
				$bottomText.html('');
				if($bottomText.css('display') == 'block') $bottomText.fadeOut();
			}
			
			$background.animate({height:($obj.height()+((hasTitle) ? 30 : 0))},400);
			
			$active.fadeOut( function(){
				$active.removeClass('active');
				$obj.fadeIn().addClass('active');
			});
		}
	}
}
$(window).bind('load', function() { 
	var timeout = setTimeout(function() { $(".imageRotator_background img").trigger("afterLoad"),4000 });
});

(function($){$.fn.picReady=function(img){
	$(this).css('display','block');
	
	/*var $thisR = $(this).closest('.imageRotator');
	
	if( typeof(timers[($thisR.attr('id'))]) == 'undefined' && $thisR.css('display') == 'block' ){
		timers[($thisR.attr('id'))] = setInterval('rotateImage("' + $thisR.attr('id') + '")', 4000);
	}*/
};})(jQuery);

$(document).ready(function() {
	var opacity = 0.4, toOpacity = 1.0, duration = 500, bottomTextOpa = opacity + 0.2;
	var hasTitle = false;	
	$('.imageRotator').each(function(){
		$(this).jcarousel({
		scroll:1,
		auto:4,
		wrap:"circular",
		visible:1,
		itemVisibleInCallback: {
			onBeforeAnimation:function(c,s){$(s).find('img').show();},
			onAfterAnimation:function(c,s ){
				var h=$(s).find('img').height();
				if(h<50)h=50;
				$(s).closest('ul.jcarousel-list').animate({height:h},200);
			}
		}
		});
	});
	$('.imageRotator_main').each(function(){
		if($(this).find('img').length>1){
			$(this).jcarousel({
			scroll:1,
			auto:5,
			wrap:"circular",
			buttonNextHTML:null,
			buttonPrevHTML:null,
			visible:1
			});
		}
	});
});



