/**********************************************************************************************

  CSS on Sails Framework
  Title: Geva
  Author: XHTMLized (http://www.xhtmlized.com/)
  Date: April 2010

***********************************************************************************************/

$(document).ready(function() {
	
	//buy tickets link
	$("#blackboard h3 a").click(function(){
		
		var url = "https://tickets.gevatheatre.org/TheatreManager/1/online?btnGetEventList&line=1&month=0&year=0&event=490&venue=0&search=";
		
		javascript:newWin=window.open(url,'ticketwindow','height=600,width=800,scrollBars=1,resizable=0');
		newWin.focus();
		
		return false;
	});
	
	
	swfobject.embedSWF("_ui/flash/heartbeat.swf", "swf-sound", "1", "1", "9.0.0", false, {}, {allowscriptaccess:true}, {});	
	soundObj = $('#swf-sound')[0];
	
	
	//generate all cufon fonts
	cufonize();
	
	function childwidth(el) {
		var width = 0;
		$(el).children().each(function () {
			var thiswidth = $(this).outerWidth(true);
			width += thiswidth;
		});
				
		return width;
	}

	function animateScroller(element, startFromRight) {
		
		startFromRight = typeof startFromRight === 'undefined' ? true : startFromRight;
		
		element = $(element);
		
		
		
		var scrollerWidth = childwidth(element.find('ul'));
		
		if (startFromRight) {
			element.css({left: element.parent().width() + 'px'});
			var progress = 0;
		}
		else {
			var progress = element.parent().width() - parseFloat(element.css('left'));
		}
		
		element.animate({left: scrollerWidth * -1 + 'px'}, (scrollerWidth + element.parent().width() - progress) * 30, 'linear', function () {
			window.setTimeout(function () {
				animateScroller(element);
			}, 1000);
		});
	}
	
	$("#ticker .scroller").each(function () {
		
		var el = $(this);
	
		animateScroller(el);
		
		el.parent().hover(function () {
			el.stop();
		},
		function () {
			animateScroller(el, false);
		});
	});
		
	var swfFauxLoop = 0;
	
	function soundOn() {

		swfFauxLoop = window.setInterval(
			function () {
				soundObj.playSound();
			}, 700);

		soundObj.playSound();
	}
	
	function soundOff() {
		window.clearInterval(swfFauxLoop);
		soundObj.stopSound();
	}
	
	$('.main-nav').bind('mouseenter', soundOn).bind('mouseleave', soundOff);
	
});


// cufon replacements
function cufonize(){
	
	Cufon('#blackboard ul.main-nav li', {
		hover: true
	});
	
	Cufon('#blackboard ul.social-media li', {
		hover: true
	});
	
	Cufon.replace('#listen h4');
	
}

// DD_belatedPNG fix for IE6 
//DD_belatedPNG.fix('.cupid-flash, .camera-flash, .speakers-flash');
