$(function(){
	browser();
	
	$("a[rel^='pp']").prettyPhoto();
	
	
	if($('body').hasClass('iPhone')){
		$('ul.gallery img').attr('width','185');	
	}else{
		$('ul.gallery li:nth-child(3n)').addClass('nrm');
	}
	
	$('div.levels').each(function(){
		 $('div.participants:last-child').addClass('last');
	});
	
	$('#lastYearsSponsors li:even').addClass('even');
	$('#lastYearsSponsors li:odd').addClass('odd');
	
	if($('html').hasClass('mac')){
		$('.macCTRL').css('display', 'block');
	}else{
		$('.pcCTRL').css('display', 'block');
	}
	
	$('#starttime').change(function(){
		$('#displaytime').val($(this).children('option:selected').val());
	});
	
	$('#downloadLogo').click(function(){
		var checked = $("input:checked").length;
		if(checked == 1){
			$('#hideLogo').slideDown();
		}else{
			alert("You must agree to the terms of use");	
		}
	});
	
	$('#backTo').click(function(){
		history.go(-1);
		return false;
	});
	
	var ad = $('#ad');
	if(ad.length && $('body').hasClass('home') == false){
		var rad = Math.floor(Math.random()*3)+1;
		if(rad == 1){
			 ad.html('<a href="http://mobile.bbweek.com" style="margin-left:-20px;"><img src="images/ad/mobile.png" alt="Mobile Baltimore Beer Week" /></a>');
		}else if(rad ==2){
			 ad.html('<a href="passport.php" style="margin-left:-20px;"><img src="images/ad/passport1a.png" alt="Get your BBW Passport" /></a>');
		}else if(rad == 3){
			 ad.html('<a href="passport.php" style="margin-left:-20px;"><img src="images/ad/passport1a.png" alt="Get your BBW Passport" /></a>');
		}else if(rad ==4){
			 ad.html('<a href="passport.php" style="margin-left:-20px;"><img src="images/ad/passport1a.png" alt="Get your BBW Passport" /></a>');
		}
	}
	
	//if($('html').hasClass('iphone')){
		//$('head').append('<meta name="viewport" content="width=device-width" /><link href="css/handheld.css" rel="stylesheet" media="screen" type="text/css" /><link rel="stylesheet" type="text/css" href="css/retina.css" media="only screen and (-webkit-min-device-pixel-ratio: 2)">');
	//}
});

function open_win(eventid){
	var eventurl="eventdetails2.php?eventid=" + eventid ;
	window.open(eventurl,'','height=470,width=760,resizable=yes,scrollbars=yes,location=yes,toolbar=yes');
	return false;
}

function open_win2(){
	window.open('eventdetailsspbw.htm','','height=470,width=755,resizable=yes,scrollbars=yes,location=yes,toolbar=yes');
	return false;
}


function slideShow(){
	var timeToSwitch = 8376 ; // 3000 = 3 seconds this is the time that a user needs to sit on the nav link before drop down menus open.
	var susanBox = $('#SusanBox');
	var sl = $('#SusanLinks');
	var sbChild = susanBox.children('div');
	var slideTimer = {};
	var i = 1;
	

	sbChild.eq(0).addClass('current').show();
	// function to allow us to call it from inside the timer, essentially a loop
	doSlide = function(){
		//slide Timer
		slideTimer = $.timer(timeToSwitch, function() {
			if(i < sbChild.length){
				$('div.current', susanBox).removeClass('current').fadeOut('slow').next().fadeIn('slow').addClass('current');
				$('a.current', sl).removeClass('current').next().addClass('current');
				i += 1;
			}else if(i == sbChild.length){
				$('div.current', susanBox).removeClass('current').fadeOut('slow');
				sbChild.eq(0).fadeIn('slow').addClass('current');
				$('a.current', sl).removeClass('current');
				$('a', sl).eq(0).addClass('current');
				i = 1;
			}
			doSlide(); // calls timer function again
		});
	}
	doSlide(); // calls timer function for the first time
	
	sbChild.each(function(){
	//for(i=0; i<sbChild.length; i++){
		sl.append('<a href="#"></a>');	
	//}
	});
	sl.children('a').eq(0).addClass('current');
	
	sl.children('a').click(function(){
		$.clearTimer(slideTimer);
		sl.children('a').removeClass('current');
		$(this).addClass('current');
		var whichOne = $(this).prevAll().length;
		$('div.current', susanBox).removeClass('current').fadeOut('slow');
		susanBox.children('div').eq(whichOne).addClass('current').fadeIn('slow');
		return false;
	});
	
} //end slideShow();




jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);
browser = function(){
	var OSName="Unknown OS";
	var browser = "";
	if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Mac";
	if (navigator.appVersion.indexOf("Win")!=-1) OSName="PC";
	bodyClass = $.browser.className+OSName
	$("body").addClass(bodyClass);
	
}
