jQuery.noConflict();
var alreadyrunflag=0 //flag to indicate whether target function has already been run
if (document.addEventListener)
	document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; docReady()}, false)
	else if (document.all && !window.opera){
	document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
	var contentloadtag=document.getElementById("contentloadtag")
	contentloadtag.onreadystatechange=function(){
	if (this.readyState=="complete"){
		alreadyrunflag=1
		docReady()
		}
	}
}
window.onload=function(){
	setTimeout("if (!alreadyrunflag){docReady()}", 0)
}
		
function docReady() {
	if (document.getElementById('home') != null) {
		//Adjust the height of the content to fit sidebar
		/*
		var sidebar = document.getElementById('sidebar');
		var topContent = document.getElementById('homeTop');
		var bottomContent = document.getElementById('homeBottom');
		var sidebarHeight = sidebar.offsetHeight;
		var topContentHeight = topContent.offsetHeight;
		var difference = sidebarHeight - topContentHeight + 10;
		bottomContent.style.height="" + difference + "px";
		*/
		
		//flickr in sidebar
		var flickrpre = '<div id="tallGrayBoxTop"></div><div id="tallGrayBoxMiddle"><h3 class="flickrh3">Flickr</h3><img id="fBigPic" src="/page/-/images/flickrLoader.gif"/><p class="fdec"></p><div id="fthumbsWrapper"><div id="fLeftA"></div><div id="rRightA"></div><div id="fthumbscont"><div id="fthumbs"></div><!--#fthumbs--></div><!--#fthumbscont--></div><!--#fthumbsWrapper--></div><!--tallGrayBoxMiddle--><div id="tallGrayBoxBottom"></div>';
		jQuery(flickrpre).insertBefore('#social-links');
        
		jQuery.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?id=36514541@N04&lang=en-us&format=json&jsoncallback=?', function(data){
			jQuery.each(data.items, function(i,item){
				//jQuery("<img/>").attr("src", item.media.m).attr('class', 'fthumbimg').appendTo("#fthumbs");
				var tstyle = 'height: 100px; width: 100px; background: url('+item.media.m+') center center no-repeat;';
				var tndesc = item.description;
				//var tndesc2 = tndesc.split('<p>')[2].replace(/<\/p>/, '');
                var tndesc2 = '';
				jQuery('<div/>').attr('style', tstyle).attr('big', item.media.m).attr('desc', tndesc2).appendTo('#fthumbs');
				if ( i == 25 ) return false;
			});
			
			var firstdesc = jQuery('#fthumbs div:first-child').attr('desc');
			var firstimg = jQuery('#fthumbs div:first-child').attr('big');
			var flickrlink = 'http://www.flickr.com/photos/kendrickmeekdotcom/';
			jQuery('#fBigPic').attr('src', firstimg);
			jQuery('.fdec').html(firstdesc + '&nbsp;<a target="_blank" href="'+flickrlink+'">See all Pictures</a>');
			jQuery('#fthumbs').children().css('cursor', 'pointer');
			
			var thmbAmt = jQuery('#fthumbs').children().size();
			var thmbWdt = 108;
			var fCurrentPosition = 0;
			
			var flb = document.getElementById('fLeftA');
			var frb = document.getElementById('rRightA');
			flb.style.cursor= 'pointer';
			frb.style.cursor= 'pointer';
			var ftcont = document.getElementById('fthumbs');
			
			frb.onclick = function() {
				
				if(Math.abs(fCurrentPosition) < (thmbWdt * (thmbAmt - 2))){
					var newPos = (fCurrentPosition - thmbWdt) + 'px';
					jQuery(ftcont).stop().animate({
							marginLeft: newPos
						}, 250, function(){
							var newp = parseFloat(newPos);
							fCurrentPosition = newp
					});
				}
			};
			
			flb.onclick = function() {
				
				if(fCurrentPosition !== 0){
					var newPos = (fCurrentPosition + thmbWdt) + 'px';
					jQuery(ftcont).stop().animate({
							marginLeft: newPos
						}, 250, function(){
							var newp = parseFloat(newPos);
							fCurrentPosition = newp
					});
				}
			};
			
			
			jQuery('#fthumbs div').click(function(){
				var tsrc = jQuery(this).attr('big');
				var tdesc = jQuery(this).attr('desc');
				jQuery('#fBigPic').attr('src', tsrc);
				jQuery('.fdec').html(tdesc + '&nbsp;<a target="_blank" href="'+flickrlink+'">See all Pictures</a>');
			});
			
		});
		
	}
	
	
	if (document.getElementById('issueSide') != null) {
		var issueSide = document.getElementById('issueSide');
		var mainContent = document.getElementById('contentMain');
		var issueSideHeight = issueSide.offsetHeight;
		var mainContentHeight = mainContent.offsetHeight;
		if(issueSideHeight > mainContentHeight) {
			mainContent.style.height="" + issueSideHeight + "px";
		}
	}
	
	/*
	if (document.getElementById('interiorS')){
		var sb = document.getElementById('sidebar');
		var cont = document.getElementById('contentMain');	
		var sHeight = sb.offsetHeight + 10;
		cont.style.height='' + sHeight + 'px';
		console.log(sHeight);
	}
	*/
	
	if(document.getElementById('home') != null) {
		/*
		eventSubmit = document.getElementById('quickEventSubmit');
		eventSubmit.onclick = function() {
			var zipCode = document.getElementById('quickEventZip').value;
			var dest = '/page/event/search_results?orderby=zip_radius&zip_radius[0]=' + zipCode + '&zip_radius[1]=50&country=US&limit=20&radius_unit=miles';
			//console.log(zipCode);
			document.location = dest;
			return false;
		}
		*/
		
		jQuery.getScript('/page/-/js/jquery.easing.1.3.js', function(){
		
			var fCont = document.getElementById('fContainer');
			var fWrap = document.getElementById('fWrapper');
			var arrows = '<div id="leftA"></div><div id="rightA"></div>';
			jQuery(fWrap).prepend(arrows);
			var la = document.getElementById('leftA');
			var ra = document.getElementById('rightA');
			var position = 0;
			la.style.cursor="pointer";
			ra.style.cursor="pointer";
			
			
			
			
			var eWidth = 662;
			var childs = jQuery(fCont).children().size();
			//console.log(childs);
			var speed = 600;
			
			function featureMoveRight(){
				if(eWidth * (childs - 1) > Math.abs(position)){
						var newPos = position - eWidth + 'px';
						//console.log(newPos);
						jQuery(fCont).stop().animate({
							marginLeft: '' + newPos + ''
						}, speed, 'easeInOutExpo', function(){
							var newPos2 = parseFloat(newPos);
							position = newPos2;
						});//fCont.animate
					}//if
			}
			function featureMoveLeft(){
				if(Math.abs(position) > 0) {
					var newPos = position + eWidth + 'px';
					jQuery(fCont).stop().animate({
						marginLeft: '' + newPos + ''
					}, speed, 'easeInOutExpo', function(){
						var newPos2 = parseFloat(newPos);
						position = newPos2;
					});//fCont.animate
				}//if
			}
			function feature_auto(){
				autoScroll = setInterval(featureMoveRight, 5000);
			}
			
			feature_auto();
			
			ra.onclick = function(){
				clearInterval(autoScroll);
				featureMoveRight();
			};//la.onclick
			
			la.onclick = function(){
				clearInterval(autoScroll);
				featureMoveLeft();
			};//ra.onclick
		
		});
	
	}//homepage detection
	
	
	
	
};//docReady
		
		
//jQuery.easing.def = "easeInOutExpo";
jQuery(function(){
	jQuery('#nav li a').stop().hover(function(){
		jQuery(this).stop().animate({
			opacity: 0
			}, 250);
		}, function() {
			jQuery(this).stop().animate({
				opacity: 1
			}, 250);
		});
});

this.label2value = function(){	

	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	jQuery("label:not(#quickEventZip)").each(function(){		
		obj = document.getElementById(jQuery(this).attr("for"));
		if((jQuery(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			jQuery(obj).addClass(inactive);			
			var text = jQuery(this).text();
			jQuery(this).css("display","none");			
			jQuery(obj).val(text);
			jQuery(obj).focus(function(){	
				jQuery(this).addClass(focused);
				jQuery(this).removeClass(inactive);
				jQuery(this).removeClass(active);								  
				if(jQuery(this).val() == text) jQuery(this).val("");
			});	
			jQuery(obj).blur(function(){	
				jQuery(this).removeClass(focused);													 
				if(jQuery(this).val() == "") {
					jQuery(this).val(text);
					jQuery(this).addClass(inactive);
				} else {
					jQuery(this).addClass(active);		
				};				
			});				
		};	
	});		
};
jQuery(document).ready(function(){
	if(document.getElementsByTagName('input') != null){
		label2value();	
	}
});