// PRELOAD IMAGES
var preImages = new Array(
"img/social-buzz.gif",
"img/social-delic.gif",
"img/social-dig.gif",
"img/social-fbook.gif",
"img/social-link.gif",
"img/social-stumble.gif",
"img/social-twit.gif"
);
var loader = new Asset.images(preImages);

// REPLACE ROCKWELL HEADERS FOR ALL BROWSERS

Cufon.replace('div.custom-message span', { hover: true, fontFamily: 'rockwell' });
Cufon.replace('div#main-content h2', { hover: true, fontFamily: 'rockwell' });
Cufon.replace('ul#bot-nav li a', { hover: true, fontFamily: 'rockwell' });
Cufon.replace('#daysuntil', { hover: true, fontFamily: 'rockwell' });
Cufon.replace('ul#section-nav li a', { hover: true, fontFamily: 'rockwell' });


// if font face isn't supported, use cufon to style the font in cicle

var isFontFaceSupported = function(){
 
  var ua = navigator.userAgent, parsed;
 
  if (/*@cc_on@if(@_jscript_version>=5)!@end@*/0) 
      return true;
  if (parsed = ua.match(/Chrome\/(\d+\.\d+\.\d+\.\d+)/))
      return parsed[1] >= '4.0.249.4';
  if ((parsed = ua.match(/Safari\/(\d+\.\d+)/)) && !/iPhone/.test(ua))
      return parsed[1] >= '525.13';
  if (/Opera/.test({}.toString.call(window.opera)))
      return opera.version() >= '10.00';
  if (parsed = ua.match(/rv:(\d+\.\d+\.\d+)[^b].*Gecko\//))
      return parsed[1] >= '1.9.1';    
 
  return false;
 
}

// add a cufoned class to nav it's been cufoned to fix padding

if (isFontFaceSupported() == false) {
Cufon.replace('#navigation li', { hover: true, fontFamily: 'Cicle' });
}

window.addEvent('domready', function() {
	if (isFontFaceSupported() == false) {
	$$('#navigation li').addClass('cufoned');
	}
	
	$('partner-slide-holder').setStyle('opacity', 0);
});

// add nav rollovers

window.addEvent('domready', function() {
	$$('#navigation li a').each(function(el){
		if (el.getParent().hasClass('selected')==false){
			el.addEvent('mouseover', function(){
				this.getParent().addClass('over');
			});
			el.addEvent('mouseleave', function(){
				this.getParent().removeClass('over');
			});
		}
	});
	$$('#bot-nav li a').each(function(el){
			el.addEvent('mouseover', function(){
				this.getParent().addClass('over');
			});
			el.addEvent('mouseleave', function(){
				this.getParent().removeClass('over');
			});
	});
});


// take a square image and put it inside of a circle
function drawMask(theImg) {

	if ($chk(theImg)) {
	
	var maskWidth = parseInt(theImg.getStyle('width'));
	var maskHeight = parseInt(theImg.getStyle('height'));
	
	if (!(Browser.Engine.trident)) {
	
	var canvas = new Element('canvas', {
    'id': 'theMask',
    'width' : maskWidth,
    'height' : maskHeight
	});
	
	canvas.inject(theImg, 'before');

     var canvas = document.getElementById("theMask");
 
      if (canvas.getContext) {
 		
 		context = canvas.getContext('2d');       
        context.beginPath();
        context.arc(Math.ceil(maskWidth/2),Math.ceil(maskHeight/2),Math.ceil(maskWidth/2),0,Math.PI*2,true);
        context.clip();

            //draw image this way
         var img = new Image();
         img.src = theImg.src;
         img.onload = function() {
                context.drawImage(img, 0, 0);
          };

      }
     } else {
      
	document.write('<v:oval style=\"width:' + maskWidth + 'px;height:' + maskHeight + 'px\" stroked=\"no\">\n<v:fill src=\"' + theImg.src + '\" type=\"frame\"></v:fill>\n</v:oval>\n');
      }
      theImg.destroy();
      }
    }
    
// animate the Register Now Burst on rollover    
    
/*window.addEvent('domready', function() {
	if ($chk($('regBurst'))) {
		
		if(isIE6){
		$('regBurst').src = "img/burst-reg-now2.gif";
		}
		
		$('regBurst').addEvent('mouseover', function(){
			var morphObject = new Fx.Morph(this.getParent().getParent(), {
    		duration: 150,
    		link: 'chain'
			});
			var morphObject2 = new Fx.Morph(this, {
    		duration: 150,
    		link: 'chain'
			});

			morphObject.start({
    		'right': 145,
    		'top' : 372,
    		'width': 217,
    		'height': 215
			});
			morphObject.start({
    		'right': 165,
    		'top' : 392,
    		'width': 177,
    		'height': 175
			});
			morphObject2.start({
    		'width': 217,
    		'height': 215
			});
			morphObject2.start({
    		'width': 177,
    		'height': 175
			});
		});
	}
});*/


// add the underline to headers and color them
 
window.addEvent('domready', function() {

	if ($chk($('main-content'))) {	
	var theHeaders = $$('div.main-content-pad h2');

	if (theHeaders.length>0) {
	
		theHeaders.each(function(el){
			
			var newLength;
			
			if ($('main-content').hasClass('home')) {
			newLength = el.offsetWidth-23;
			} else {
			newLength = el.offsetWidth-32;
			}
			
			if (el.getNext().hasClass('h2sub')){
			
				if (el.getNext().getElement('span').offsetWidth > newLength) {
					newLength = el.getNext().getElement('span').offsetWidth;
				}
			
			}
			
			var theUnderline = new Element('div', {
    		'class': 'h2Underline',
    		'styles': {
        		'height': '1px',
        		'width' : newLength,
        		'overflow' : 'hidden'
    		}
			});
			
			if (el.getNext().hasClass('h2sub')){
			theUnderline.inject(el.getNext(), 'after');
			} else {
			theUnderline.inject(el, 'after');
			}
		}); 
				
		}
	
	// take unwanted borders off of first and last section
	$$('.main-content-pad:first-child').setStyle('borderTop', 'none');
	$$('.main-content-pad:last-child').setStyle('borderBottom', 'none');
	$$('.main-content-pad p:last-child').setStyle('marginBottom', 0);
	
	}
}); 


// pop up the footer share menu

window.addEvent('domready', function() {
	if ($chk($('footer-links'))) {	
		
		/*$('footer-share').addEvent('click', function(e){
			e.stop();
		});*/
			
		$('footer-share').addEvent('mouseover', function(){
			$('share-links').setStyles({
			'display' : 'block'
			});
		});
		$('footer-share').addEvent('mouseleave', function(){
			$('share-links').setStyles({
			'display' : 'none'
			});
		});
		
		$('footer-tix').addEvent('mouseover', function(){
			$('tix-roll').setStyles({
			'display' : 'block'
			});
		});	
		$('footer-tix').addEvent('mouseleave', function(){
			$('tix-roll').setStyles({
			'display' : 'none'
			});
		});
		
		$('footer-download').addEvent('mouseover', function(){
			$('cal-roll').setStyles({
			'display' : 'block'
			});
		});	
		$('footer-download').addEvent('mouseleave', function(){
			$('cal-roll').setStyles({
			'display' : 'none'
			});
		});		

		
		
		}
});
 
 
// handle the secondary nav links

// add the smooth scrolls
window.addEvent('domready', function() {

	var theAnchors = $$('.smoothAnchors');
	if (theAnchors.length > 0) {

	var mySmoothScroll = new SmoothScroll({
    	links: '.smoothAnchors',
    	wheelStops: false
	});
	
	$$('ul#section-nav li a').each(function(el){
		var morphObject = new Fx.Morph(el, {
    		duration: 100,
    		link: 'chain'
		});
		
		el.addEvent('mouseover', function(){
		morphObject.start({
    		'paddingLeft': 50
			});
		});
		el.addEvent('mouseleave', function(){
		morphObject.start({
    		'paddingLeft': 14
			});
		});
	});
	
	}

});

 
// tile the bio and speaker boxes

window.addEvent('domready', function() {
	
	if ($chk($('confirmed-speakers-list'))) {
	
	
	var ie6OldHeight;
	var ie6NewHeight;
	var ie6Difference;
	if (isIE6) {
	ie6OldHeight = $('container').offsetHeight;
	}
	
	
	var theBlockHeight = 0;
	var theBlocks = $$('ul#confirmed-speakers-list li');
	for (i=0;i<theBlocks.length;i++) {
		if (theBlocks[i].offsetHeight > theBlockHeight) { theBlockHeight = theBlocks[i].offsetHeight; }
	}
	theBlocks.setStyle('height', theBlockHeight-18);
	
	var theNewHeight = theBlockHeight*Math.ceil((theBlocks.length/4))+(20*theBlocks.length/4);
	
	$('confirmed-speakers-list').setStyle('height', theNewHeight);
	$$('ul#confirmed-speakers-list li').setStyle('float', 'left');
	
	
	theBlocks.each(function(el){
		el.getElements('a').addEvent('mouseover', function(){
			el.tween('opacity', .65);
		});
		el.getElements('a').addEvent('mouseleave', function(){
			el.tween('opacity', 1);
		});
	});
	
	}
	
	if ($chk($('confirmed-partners-list'))) {
	
	
	var ie6OldHeight;
	var ie6NewHeight;
	var ie6Difference;
	if (isIE6) {
	ie6OldHeight = $('container').offsetHeight;
	}
	
	
	var theBlockHeight = 0;
	var theBlocks = $$('ul#confirmed-partners-list li');
	for (i=0;i<theBlocks.length;i++) {
		if (theBlocks[i].offsetHeight > theBlockHeight) { theBlockHeight = theBlocks[i].offsetHeight; }
	}
	theBlocks.setStyle('height', theBlockHeight-18);
	
	var theNewHeight = theBlockHeight*Math.ceil((theBlocks.length/4))+(20*theBlocks.length/4);
	
	$('confirmed-partners-list').setStyle('height', theNewHeight);
	$$('ul#confirmed-partners-list li').setStyle('float', 'left');
	
	
	theBlocks.each(function(el){
		el.getElements('a').addEvent('mouseover', function(){
			el.tween('opacity', .65);
		});
		el.getElements('a').addEvent('mouseleave', function(){
			el.tween('opacity', 1);
		});
	});
	
	}
	
	
});	 
    
    
  // the top scroller
  
  var scrollContentWidth = 0;
 
  
  window.addEvent('load', function() {
  	var imageObjects = $('gallery-content').getElements('img');
  	for (i=0;i<imageObjects.length;i++) {
		scrollContentWidth += imageObjects[i].offsetWidth;
		scrollContentWidth += 10;
	}
	$('gallery-content').setStyles({
		'width' : scrollContentWidth,
		'overflow' : 'hidden'
		});
		
		
	galleryScroll = new Fx.Scroll('gallery-mask', {
	wait: false,
	duration: 800,
	transition: Fx.Transitions.Circ.easeOut
	});
	
	doScroll();
  });
  
  function doScroll() {
  	var x=0;
  	var scrollDist = 758;
  	
  	scrolling=setInterval(function() {
  	
  	galleryScroll.start(x, 0);
  	if (x+scrollDist > scrollContentWidth) {
  	x=0;
  	} else {
  	x+=scrollDist;
  	}
  	
  	}, 2500);
  	
  }
  
  // rotate sponsors
function partnerSlide( Obj, theDuration ){
	// Version 0.2; Created by Kow, 2008; http://skyweb.hu/kow
	var pass = this;
	// initializing
	this.curA = 0;
	this.slides = Obj;
	this.slides.each( function( a, index ){ 
		if( index > 0 ) a.fade(); 
		a.set('morph', { duration: theDuration });
	}, this);
	this.next = function(){
		pass.curA++;
		this.slides.each( function( a, index ){ 
			a.morph({ opacity: 0 });
		}, this);
		if( pass.curA == this.slides.length ) pass.curA = 0;
		this.slides[ pass.curA ].morph({ opacity: 1 });
	}
	this.prev = function(){
		pass.curA--;
		this.slides.each( function( a, index ){ 
			a.morph({ opacity: 0 });
		}, this);
		if( pass.curA < 0 ) pass.curA = this.slides.length - 1;
		this.slides[ pass.curA ].morph({ opacity: 1 });
	}
}

window.addEvent('load', function() {

// shuffle the elements
var theLinks = $$('#partner-slide-holder a').shuffle();
theLinks.inject($('partner-slide-holder'));

setTimeout(function(){$('partner-slide-holder').tween('opacity', 1)}, 400);
if ($$('div#partner-slide-holder a').length > 1) {
sshow5 = new partnerSlide( $$('div#partner-slide-holder a'), 2000 );
sshow5.next.periodical( 5000, sshow5);
}

});
 
 
// this randomizes an array

Array.implement({
shuffle:function() {
this.sort(function (x,y) { return Math.floor(Math.random()*3)-1; });
return this;
}
});  
