var $j = jQuery.noConflict();

var activeItem = 1;
var t = null;
var auto = 3000;
var slide_auto = true;
var speed = 1000;

$j(document).ready(function(){
    
	setTimeout(function(){
		$j('INPUT.auto-hint').each(function(i, el){
			if($j(this).val() == ''){
				$j(this).val($j(this).attr('title'));
			}
			$j(el).focus(function(){
				if ($j(this).val() == $j(this).attr('title')) {
					$j(this).val('');
				}       
			});
			$j(el).blur(function(){
				if ($j(this).val() == '') {
					$j(this).val($j(this).attr('title'));
				}
			});
		});
	},1300)
	
	//Home Content Slider
	$j('.rotator LI').hide();
	$j('.rotator LI:first').show();
	
	$j('.rotator-nav a').click(function(){
		activeItem = parseInt($j(this).attr("class"));
		if ( $j('.rotator-nav a.'+activeItem).hasClass('active') ) return false;
		clearTimeout(t);
		slide_auto = false;
		customSlider();
	});

	t = setTimeout("nextItem();customSlider();",auto);
	
	setTimeout(addHint, 1000);
	
});

function customSlider(){
	if ( parseInt($j(".rotator").css("opacity")) < 1.0 ) return false;

	$j('.rotator').fadeTo(speed,"1500",function(){
		$j('.rotator LI').fadeOut(1000);
		$j('.rotator LI').each(function(i,el){if ( (i+1) == activeItem ) $j(this).fadeIn(1000);});
		$j('.rotator-nav a').removeClass('active');
		$j('.rotator-nav a.'+activeItem).addClass('active');
		//$j('.rotator').fadeTo(speed,"1",function(){
		if (slide_auto) { t = setTimeout("nextItem();customSlider();",auto); }
		else t = setTimeout("customSlider();",auto);
		slide_auto = true;
		});

	return false;
}
function prevItem(){
	if ( activeItem <= 1) activeItem = $j(".rotator UL LI").length;
	else activeItem--;
}
function nextItem(){
	if ( activeItem >= $j(".rotator UL LI").length) activeItem = 1;
	else activeItem++;
}

function addHint(){
	$j('.top-form .gsom_sfi input').attr({ title: "special offers via email" }).addClass('auto-hint');
}


(function($j) {
	$j.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $j(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
					var w = el.width();
					
					var t = $j(this.cloneNode(true)).hide().css({
                        'position': 'absolute',
                        'width': 'auto',
                        'overflow': 'visible',
                        'max-width': 'inherit'
                    });
					el.after(t);
					
					var text = originalText;
					while(text.length > 0 && t.width() > el.width()){
						text = text.substr(0, text.length - 1);
						t.html(text + "...");
					}
					el.html(t.html());
					
					t.remove();
					
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		} else return this;
	};
})(jQuery);

 
$j(document).ready(function() {
	$j("label + input").css("float", "left");
	$j("h2 + h3").addClass("js-h2-h3");
	$j("blockquote + p").addClass("js-blockquote-p");	
	$j("h2 + p").addClass("js-h2-p");
	$j("label + input[type=\"text\"]").addClass("text");
	$j("form.half-width li").append("<div class=\"clear\"></div>");
    $j('UL.list LI:last').addClass('last');
    $j('UL.venue-subnav LI:last').addClass('last');
    $j('UL.list LI:first').addClass('first');
    $j('.footer .black UL LI A:last').addClass('last');
    $j('.upcoming-events ul li span.name').ellipsis();
});
