/* set up custom fonts */
Cufon.replace('ul.cols > li > h2', { fontFamily: 'SerifaStdBold' });
Cufon.replace('h1[class!=no-cufon]', { fontFamily: 'SerifaStdBold' });
Cufon.replace('#headline h1 strong', { fontFamily: 'SerifaStdBlack' });
Cufon.replace('#headline h1 span', { fontFamily: 'SerifaStdRoman' });
Cufon.replace('.track-listing h2, .event-info h2, .event-info h3', { fontFamily: 'SerifaStdBold' });

/* setup heading opacity */
$(document).ready(function()
{
	var head = $('#head');
	
	/* add new opacity layer */
	var o = $('<div />')
		.addClass('opacity')
		.insertBefore(head);
		
	o.css({
		opacity:0.8, 
		position:'absolute', 
		top:0, 
		left:0, 
		width: '100%',
		backgroundColor: head.css('background-color')
	})
	.height(head.height());
	
	head.css({
		position:'relative',
		zIndex:5,
		backgroundColor:'transparent'
	});
});

/* setup footer opacity */
$(function()
{
	var content = $('#content');
	
	var o = $('<div />')
		.addClass('opacity')
		.height(content.height())
		.css({opacity: 0.8})
		.prependTo(content);
		
	content.css({backgroundColor: 'transparent'});
})

/* setup dl.img banners */
$(function() 
{
	var dl = $('dl.img');
	
	if(dl.length)
	{
		var dt = $('dt', dl);
		var o = $('<div />').addClass('opacity');
		
		o.css({
			height: dt.height() + 'px',
			width: dt.width() + 'px',
			opacity: 0.8
		})
		.prependTo(dt);
		
		dt.css({backgroundColor: 'transparent'});
	}
});

/* handle image hover transitions */
$(function() 
{
	var border = $('dl.img');
	
	border
		.hover(function(e) {
			e.preventDefault();
			$('img', this).stop().animate({opacity: 0.7}, 500);
			return false;
		},
		function(e) {
			e.preventDefault();
			$('img', this).stop().animate({opacity: 1}, 500);
			return false;
		});
});

$(window).ready(function()
{
	var backgrounds = new Array();
	/**
	* Setup as many page backgrounds as we want,
	* using a basic array
	*/
	/*backgrounds['index.html'] = 'home.jpg';
	backgrounds['event.html'] = 'event.jpg';
	backgrounds['event-listing.html'] = 'event-listing.jpg';
	backgrounds['about.html'] = 'home.jpg'; */
	backgrounds['default.aspx'] = 'about.jpg';
	backgrounds['blog.aspx'] = 'about.jpg';
	/*backgrounds['EventTemplate.aspx'] = 'event.jpg';*/
	backgrounds['EventListing.aspx'] = 'event-listing.jpg';
	/*backgrounds['About.aspx'] = 'about.jpg'; */
	backgrounds['videogallery.aspx'] = 'about1.jpg';

	function _getUrlBackground(url)
	{
		for(var i in backgrounds)
		{
			if(i.match(new RegExp(url)))
			{
				return backgrounds[i];
			}
		}
		return false;
	}
	
	/* preload a single image */
	function _preloadImage(image)
	{
		var img = new Image();
		var path = 'assets/images/backgrounds/';
		$(img).attr('src', path + image);
		return $(img);
	}
	
	/* preload all of our backgrounds */
	function _preloadImages()
	{
		for(var i in backgrounds)
		{
			_preloadImage(backgrounds[i]);
		}
	}
	
	/* setup background container */
	function _setupBackgroundContainer()
	{
		var wrapper = $('<div />');
		var container = $('<div />');
		var body = $('body');
		var width = 0;
		
		body
			.css({
				position: 'relative'
			})
		
		container
			.prependTo(wrapper);
			
		wrapper
			.css({
				position: 'absolute',
				top: 0,
				left: 0,
				width: '100%',
				overflow: 'hidden'
			})
			.attr('id', 'backgroundContainer')
			.height($(document).height()).prependTo(body);
		
		/* create child container elements */
		for(var i in backgrounds)
		{
			var child = $('<div />');
			
			child.attr('bgurl', i);
			
			child.css({
				float: 'left',
				display: 'inline'
			});
			
			var img = _preloadImage(backgrounds[i]);
			
			child.append(img);
			
			container.append(child);
			
			width+= img.width();
		}
		
		/**
		 * set container width to accomodate
		 * children horizontally
		 */
		container.width(99999);
	}
	
	_preloadImages();
	_setupBackgroundContainer();
	
	$('ul.nav a')
		.click(function(e)
		{
			e.preventDefault();
			
			var url = $(this).attr('href');
			var _bg = _getUrlBackground(url);
			var el = $('#backgroundContainer div img[src$='+_bg+']').parent();
			
			/* only scrollto, if we've got a url set up for that */
			if(el.length)
			{
				$('#backgroundContainer').scrollTo(el, 1000, {
					onAfter: function()
					{
						window.location.href = url;
					}
				});
			}
			else
			{
				window.location.href = url;
			}

		});
	
	$('img').load(function()
	{
	for(var i in backgrounds)
	{
		var url = window.location.href;
		
		if(url.match(new RegExp(i)))
		{
			var default_background = $('#backgroundContainer div[bgurl^='+i+']');
			if(default_background.length)
			{
				$('#backgroundContainer').scrollTo(default_background, 0);
				break;
			}
		}
	}
	});
});

$(document).ready(function()
{
	$('body').css({backgroundImage: 'none'});
});






/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

// jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function(f,h,i){function k(a,c){var b=(a[0]||0)-(c[0]||0);return b>0||!b&&a.length>0&&k(a.slice(1),c.slice(1))}function l(a){if(typeof a!=g)return a;var c=[],b="";for(var d in a){b=typeof a[d]==g?l(a[d]):[d,m?encodeURI(a[d]):a[d]].join("=");c.push(b)}return c.join("&")}function n(a){var c=[];for(var b in a)a[b]&&c.push([b,'="',a[b],'"'].join(""));return c.join(" ")}function o(a){var c=[];for(var b in a)c.push(['<param name="',b,'" value="',l(a[b]),'" />'].join(""));return c.join("")}var g="object",m=true;try{var j=i.description||function(){return(new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}()}catch(p){j="Unavailable"}var e=j.match(/\d+/g)||[0];f[h]={available:e[0]>0,activeX:i&&!i.name,version:{original:j,array:e,string:e.join("."),major:parseInt(e[0],10)||0,minor:parseInt(e[1],10)||0,release:parseInt(e[2],10)||0},hasVersion:function(a){a=/string|number/.test(typeof a)?a.toString().split("."):/object/.test(typeof a)?[a.major,a.minor]:a||[0,0];return k(e,a)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(a){if(!a.swf||this.expressInstallIsActive||!this.available&&!a.hasVersionFail)return false;if(!this.hasVersion(a.hasVersion||1)){this.expressInstallIsActive=true;if(typeof a.hasVersionFail=="function")if(!a.hasVersionFail.apply(a))return false;a={swf:a.expressInstall||this.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:this.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:a.swf,type:"application/x-shockwave-flash",id:a.id||"flash_"+Math.floor(Math.random()*999999999),width:a.width||320,height:a.height||180,style:a.style||""};m=typeof a.useEncode!=="undefined"?a.useEncode:this.encodeParams;a.movie=a.swf;a.wmode=a.wmode||"opaque";delete a.fallback;delete a.hasVersion;delete a.hasVersionFail;delete a.height;delete a.id;delete a.swf;delete a.useEncode;delete a.width;var c=document.createElement("div");c.innerHTML=["<object ",n(attrs),">",o(a),"</object>"].join("");return c.firstChild}};f.fn[h]=function(a){var c=this.find(g).andSelf().filter(g);/string|object/.test(typeof a)&&this.each(function(){var b=f(this),d;a=typeof a==g?a:{swf:a};a.fallback=this;if(d=f[h].create(a)){b.children().remove();b.html(d)}});typeof a=="function"&&c.each(function(){var b=this;b.jsInteractionTimeoutMs=b.jsInteractionTimeoutMs||0;if(b.jsInteractionTimeoutMs<660)b.clientWidth||b.clientHeight?a.call(b):setTimeout(function(){f(b)[h](a)},b.jsInteractionTimeoutMs+66)});return c}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject);
