$(document).ready( function() {


		//alert('herp');
		socMediaInit();
		
		sliderInit();
		
});

var current = 0;
var msca = new Array();

var timer;

function sliderInit () {
	
	var i = 0;
		
	$(".sln-button").each(function () {
			var mi = i;
			msca.push(i);
			i++;
		
		$(this).click(function (e) {
			e.preventDefault();
			
			//alert(msca[mi]);
			
			if ($("#main_home_slider_content").is(":animated") != true && current != msca[mi]) {
				
				clearTimeout(timer);
				
				$(".selected").removeClass('selected');
				
				if (current < msca[mi]) {
	
					$("#main_home_slider_content").animate({
						left: '-='+((msca[mi]-current)*919)+"px"
					}, 750);
					
					current = msca[mi];
				
					//alert(msca[mi]-current);
					
				} else if (current > msca[mi]) {
	
					$("#main_home_slider_content").animate({
						left: '+='+((current-msca[mi])*919)+"px"
					}, 750);
					
					current = msca[mi];
					//alert(msca[mi]-current);
					
				}
											
				$(this).addClass('selected');
				
				getLink();
				
			}
			
		});
		
	}); // End SLN function
	
	$('#sln-back').click(function (e) {
		e.preventDefault();
		clearTimeout(timer);
		
		$(".selected").removeClass('selected');
		
		if (current != 0 && current > 0) {
			
			current--;
			
			$("#main_home_slider_content").animate({
				left: '+=919px'
			}, 750);
			
		} else {
			
			$("#main_home_slider_content").animate({
				left: '-='+(919*(msca.length-1))+'px'
			}, 750);
			
			current = msca.length-1;
			//alert(current);
			
		}

		getLink();
		
		$("#sln-"+(current+1)).addClass('selected');
		
		//alert("#sln-"+(current+1));
		
	});
	
	$('#sln-next').click(function (e) {
		e.preventDefault();
		clearTimeout(timer);
		
		current++;
		
		$(".selected").removeClass('selected');
		
			if (current < msca.length) {
				
				$("#main_home_slider_content").animate({
					left: '-=919px'
				}, 750);
				
			} else if (current >= msca.length) {
				
				$("#main_home_slider_content").animate({
					left: '+='+(919*(msca.length-1))+'px'
				}, 750);
				
				current = 0;
				//alert(current);
				
			}
			
		$("#sln-"+(current+1)).addClass('selected');
		
		getLink();
		
	});
	
	$("#sln-"+(current+1)).addClass('selected');
	
		
	timer = setTimeout('phase()', 5000);
	getLink();
	
}

function phase () {
	
	current++;
	clearTimeout(timer);
	
	if (current < msca.length) {
		
		$("#main_home_slider_content").animate({
			left: '-=919px'
		}, 750, function () {
			
			timer = setTimeout('phase()', 5000);
			
		});
		
	} else if (current == msca.length) {

		$("#main_home_slider_content").animate({
				left: '0px'
		}, 750, function () {
			
			timer = setTimeout('phase()', 5000);
			
		});
		current = 0;
	}
	
	$(".selected").removeClass('selected');
	
	$("#sln-"+(current+1)).addClass('selected');
	
	getLink();
	
}

function getLink () {
	
	var slink = $("#mls-"+(current+1)).attr('href');
	
	$("#main_home_slider_distress").attr('href', slink);
	
}

function socMediaInit () {

		var num = 0;
		var cta = new Array();
		
		$("#social-media a.icon").each( function () {
			
			var topnum = num * 50;
			var abo = num;
			num++;
			cta.push('#mt'+num);
			//alert('push# = '+abo+" stored = "+cta[abo]);
			$(this).mouseenter(function (e) {
				//alert(cta[abo]+" in");
				var w = $(cta[abo]).outerWidth();
				
				if ( $(this).parent("div:animated") ) {
					$(cta[abo]+":animated").stop();
				}
				
				$(cta[abo]).animate({
					left: "-"+w,
					opacity: 1,
					alpha: 1
				},250).css('display', 'block').css('z-index', '9999');
				
			});
			
			$("#social-media > div").mouseenter( function () {

				var w = $(cta[abo]).outerWidth();
				if ($(cta[abo]).is(":animated")) {
					$(cta[abo]+":animated").stop();
					
				}		
			
				$(cta[abo]).animate({
					left: "-"+w,
					opacity: 1,
					alpha: 1,
					zindex: 9999
				},250).css('display', 'block').css('z-index', '9999');
						
			});
			
			$("#social-media > div").parent("*").mouseleave(function () {
				var w = $(cta[abo]).outerWidth()-5;
				//alert(cta[abo]+" out");
				
				$(cta[abo]).animate({
					left: "-"+w,
					opacity: 0,
					alpha: 0,
					zindex: 0
				},750, function(e) {
					$(this).css('display', 'none').css('z-index', '0')
				});
				
			});
						
			$(this).parent("li").mouseleave( function (e) {
				var w = $(cta[abo]).outerWidth()-5;
				//alert(cta[abo]+" out");
				
				$(cta[abo]).animate({
					left: "-"+w,
					opacity: 0,
					alpha: 0,
					zindex: 0
				},750, function(e) {
					$(this).css('display', 'none').css('z-index', '0')
				});
				
			});
			
			var ml = $(cta[abo]).outerWidth()-5;
			$("#mt"+num).css('top',topnum+'px').css('left', -ml+'px').css('filter', 'alpha(opacity=0)');
		});
}

	$(window).scroll( function () {
		if ( $(window).scrollTop() < 195 ) {
				
			if ( $("#iconfloat").is(":animated") ) {
				$("#iconfloat:animated").stop();
			} 

			$("#iconfloat").animate({
				top: "0px"
			}, 250);
			
		} else {

			var dersh = $(window).scrollTop() - 195;
				
			if ( $("#iconfloat").is(":animated") ) {
				$("#iconfloat:animated").stop();
			} 

			$("#iconfloat").animate({
				top: dersh+"px"
			}, 250, function (e) {
				//alert(dersh);
			});		
			
		}
	});

	$(window).scroll(function () {

		if ($('#innernav-list').length && $(window).scrollTop() < 290) {
		
			$('#innernav-list').animate({
				top: "120px"
			}, 250);
			
		} else {
			
			var herp = $(window).scrollTop() - 195;
					
			if ( $("#innernav-list").is(":animated")) {
				$("#innernav-list:animated").stop();
			} 
				$("#innernav-list").animate({
					top: herp+"px"
				}, 250);		
			
		}

	});

$(document).ready(function () {


	$(".enews_field").focus(function(){
	//	alert('search test');
		if(this.value == 'Email Address') {
			this.value=' '
		}
	
	});
	
	$(".enews_field").blur( function (){
		if(this.value==' ') {
			this.value='Email Address'
		}
	
	});


	if($("#innernav-list").length) {
		
		$("#innernav-list a").each(function () {
			$(this).click(function (e) {
				e.preventDefault();
				var newTarg = $(this).attr('href');
				
				var newPos = $('a[name="'+newTarg.replace(/\#/g,"")+'"]').offset();
				//alert(newTarg+" "+newPos.top);
				if (newPos != null) {
					
					autoscroll = true;
					
					$('body,html').animate({
						scrollTop: (newPos.top-150)+"px"
					}, 1000);
		
					$("#innernav-list").animate({
						top: (newPos.top-150)+"px"
					}, 1000);
				}
				
			});
		});
		
	}
	
});


$(document).ready ( function () {

	$('.galaxiead_closebutton').click(function (e) {
	
		e.preventDefault();
				
		var gaw = $('.galaxiead').outerWidth();
		
		$('.galaxiead').animate({
			left: gaw+'px'
		}, 250);
		
	});
	
});	
	
		
	var cfic = 0;
	var fadeTimer;
	var cfit = 0;


function calStart () {
	
	fadeTimer = setTimeout('calFade()', 5000);
	
	$('.calendar-fader').each(function () {
		cfit++;	
	});
	
}

function calFade () {
	
	clearTimeout(fadeTimer);
	
	$('.current-image').fadeOut(500).removeClass('current-image');
		
	cfic++;
	
	if (cfic >= cfit) {
		cfic = 0;
	}
	
	$("#cfi-"+cfic).fadeIn(500, function () {
	
		fadeTimer = setTimeout('calFade()', 5000);
		
	}).addClass("current-image");
	
	//var IL = $("#cfil-"+cfic).attr('href');
	
	//$("#calendar-link-slider").attr("href",IL);
	
	//$("#cfi-"+cfic).addClass('fader-current');
	
	
	
}

function timerStop () {
	clearTimeout(fadeTimer);
}

$(document).ready(function () {

	var rand = Math.ceil(Math.random()*3);
	/*
	$("body").css("background", "url('http://www.winnipegfolkfestival.ca/wp-content/themes/folk_festival/images/background_v"+rand+".jpg') left top #6d441c");
	*/
	
		calStart();
		
		var IL = $("#cfil-"+cfic).attr('href');
	
		$("#calendar-link-slider").attr('href', IL);

});

/*  StatCounter Code */

today = new Date();
Festival = new Date("July 4, 2012")
msPerDay = 24 * 60 * 60 * 1000 ;
timeLeft = (Festival.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);




