$(function () {	
	$("#CalendarSeason ul").idTabs();
	$("#myform").validate();

	$('#shipping_same').click(function() {
		if($('input[name=shipping_same]').is(':checked')){
			$('#shipping_first_name').val($('#first_name').val());
			$('#shipping_last_name').val($('#last_name').val());
			$('#shipping_address').val($('#address').val());
			$('#shipping_address2').val($('#address2').val());
			$('#shipping_city').val($('#city').val());
			$('#shipping_state').val($('#state').val());
			$('#shipping_zip').val($('#zip').val());
			$('#shipping_country_code').val($('#country_code').val());
		}
		else{
			$('#shipping_first_name').val('');
			$('#shipping_last_name').val('');
			$('#shipping_address').val('');
			$('#shipping_address2').val('');
			$('#shipping_city').val('');
			$('#shipping_state').val('');
			$('#shipping_zip').val('');
			$('#shipping_country_code').val('');
		}
	});	
});


Cufon.replace('#navigation li a',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#HeaderTop li',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#HomeSlideshow .message h2',{hover: true, fontFamily: 'Gotham Light'});
Cufon.replace('#HomeSlideshow .message p',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#NewsBar h4',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#UpcomingEvents h3',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#UpcomingEvents h4',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#UpcomingEvents h5',{hover: true, fontFamily: 'Sentinel Semibold'});
Cufon.replace('#UpcomingEvents p',{hover: true, fontFamily: 'Gotham Book'});
Cufon.replace('#Footer h5',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#TitleCol h2',{hover: true, fontFamily: 'Gotham Book'});
Cufon.replace('#TitleCol h3',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#SubCol h3',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#BodyText p.quote',{hover: true, fontFamily: 'Sentinel Book Italic'});
Cufon.replace('#BodyText .artist h4',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#LeftCol h3',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('h3.calendartitle',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#VenueKey',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#BodyText #RightCol .quote p',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#BodyText p.source',{hover: true, fontFamily: 'Sentinel Book Italic'});
Cufon.replace('#MainCol h3',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#HomeCalendar th',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#HomeCalendar td',{hover: true, fontFamily: 'Gotham Narrow Medium'});
Cufon.replace('#HomeCalendar p',{hover: true, fontFamily: 'Gotham Narrow Medium'});
Cufon.replace('#BodyText .artistblog h4',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('.watchListenOverview .caption',{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#socialHeader h4, #BodyText .moreinfo h5',{hover: true, fontFamily: 'Gotham Medium'});


function renderCufon() {
//	Cufon.replace('.qtip h3, .qtip h4',{hover: true, fontFamily: 'Gotham Medium'});
//	Cufon.replace('.InnerPopup h3, .InnerPopup h4',{hover: true, fontFamily: 'Gotham Medium'});
	
}

function removeActiveLI(){
	$('.PopupSlide li').removeClass('activeLI');	
}

function popupCycle() {
	clearTimeout();
	
	/* 
	$('.InnerPopup').cycle({
		fx: 'scrollHorz',
		speed:   300, 
		timeout: 0,
		pager:  '.PopupSlide',
		pagerAnchorBuilder: function(idx, slide) { 
			return '<a href="#"></a>'; 
		}
	});
	*/
	
	// new code for next/prev
	$('.InnerPopup').cycle({
		fx: 'scrollHorz',
		speed:   300, 
		timeout: 0,
		next: '.next',
		prev: '.prev',
		nowrap: true,
		prevNextEvent:'click.cycle',
		onPrevNextEvent: function(isNext, ind, slideElement) {
			count = $(slideElement).parent().children().length -1;
			ul = $(slideElement).parent().next();
			ul.children().removeClass('disabled');
			
			// disable the next/prev when at end/beginning of slideshow
			if (!isNext && ind == 0) {
				ul.children('li:eq(1)').addClass('disabled');
			}
			if (isNext && ind == count) {
				ul.children('li:eq(2)').addClass('disabled');
			}
		}
	});
	
	$('.PopupSlide li').fadeIn(); 
	$('.slide1').parent().addClass('activeLI');	


	$('.slide1').click(function() {
		$('.InnerPopup').cycle(0); 
		removeActiveLI();
		$(this).parent().addClass('activeLI');	
		return false; 
	});

	$('.slide2').click(function() { 	
		$('.InnerPopup').cycle(1); 
		removeActiveLI();
		$(this).parent().addClass('activeLI');
		return false; 
	});

	$('.slide3').click(function() { 
		$('.InnerPopup').cycle(2); 
		removeActiveLI();
		$(this).parent().addClass('activeLI');		
		return false; 
	});

	$('.slide4').click(function() { 
		$('.InnerPopup').cycle(3); 
		removeActiveLI();
		$(this).parent().addClass('activeLI');
		return false; 
	}); 
	
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
	    $(pager).find('li').removeClass('activeLI')
	        .filter('li:eq('+currSlideIndex+')').addClass('activeLI');
	};
	
}

function prePopup() {
	setTimeout(popupCycle,1100);
}



$('#NewsBar ul').cycle({
    delay:  1500, 
	speed:  1500,
	random: 0
});

$(function() {
	
	
	$('.eventartists').columnize({columns:2});
	
	$('.calendartitle').toggle(function() {
		$('.monthdropdown').show();
	}, function() {
		$('.monthdropdown').hide();
	});
	
	if ($('#HomeSlideshow').length > 0){
		
		// init slideshow
	    $('#HomeSlideshow').cycle({ 
			fx: 'fade',
	        speed: 1000,
			timeout: 8000,
			pager:  '#SliderNav',
			pagerAnchorBuilder: function(idx, slide) { 
			        return; 
			    }
	    });
	    $('#goto1').click(function() { 
	        $('#HomeSlideshow').cycle(0); 
	        return false; 
	    });
	    $('#goto2').click(function() { 
	        $('#HomeSlideshow').cycle(1); 
	        return false; 
	    });
	    $('#goto3').click(function() { 
	        $('#HomeSlideshow').cycle(2); 
	        return false; 
	    });
	    $('#goto4').click(function() { 
	        $('#HomeSlideshow').cycle(3); 
	        return false; 
	    });
	 	$('#goto5').click(function() { 
	        $('#HomeSlideshow').cycle(4); 
	        return false; 
	    });

		// variables for cookie
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + 60*60*24*30 /* one month */);
		var datestring = exdate.toUTCString(),
		found = 0;
	
		// find cookie
		cookies = document.cookie.split(';');
		
		for (i=0;i<cookies.length;i++){
			var crumbs = cookies[i].split("=");
			if (crumbs[0] == (' cms_newsletter' || 'cms_newsletter')) {
				found = 0;
				return;
			} else {
				found +=1;
			}
		}
	}
	if (found > 0 && $('#newsletter').length > 0) {
		// not found so set the cookie, then show the newsletter
		document.cookie = "cms_newsletter=1; expires="+datestring; 

		Cufon.replace('#newsletter p',{hover: true, fontFamily: 'Gotham Book'});
		Cufon.replace('#newsletter label, #newsletter a.sign_up',{hover: true, fontFamily: 'Gotham Medium'});

		$('#newsletter').jqm({
			toTop: true,
			overlay: 45,
			onShow: function(hash) { 
				hash.o.hide();
				hash.o.fadeIn(500);
				hash.w.fadeIn(1000);
			},
			onHide: function(hash) {
				_id = "#"+hash.w.attr('id'); 
				hash.w.fadeOut(500);
				hash.o.fadeOut(500, function(){
					$(this).remove();
				}); 
			}
		});
		setTimeout(function(){
			$('#newsletter').jqmShow();
		}, 5000);
		
		$('#newsletter a.sign_up').click(function(){
			$('#newsletter_form').find(':input').each(function(ind){
				if ($(this).hasClass('email') && $(this).val().indexOf('@') == -1){
					$(this).addClass('error');
					$(this).val('Enter a properly formatted email address.');
				}
				if ($(this).val() == ''){
					$(this).addClass('error');
					$(this).val('Please do not leave this field blank.');
				}
				if ($(this).hasClass('error')){
					valid = false;
				}
				$(this).focus(function(){
					$(this).removeClass('error').val('');
				});
			});
			$('#newsletter_form').find('.error').length > 0 ? valid = false : valid = true;
			if (valid) {
				$('#newsletter_form').submit();
			}
		});
	}
	
	$('.eventprogram li a').click(function() {
		$(this).parent().find('.audioplayer').slideToggle(300);
	});
	
	$('.tracklist li a').click(function() {
		$(this).parent().parent().find('.audioplayer').slideToggle(300);
	});	
	
	$('.venuekeytoggle').click(function() {
		$('#VenueKey').slideToggle(300);
	});

	$('.hidebutton').click(function() {
		$('#VenueKey').slideUp();
	});
	
	$('.davidfinckel').qtip({
		content: {
			url: 'artistpopup.html',
			data:  { id: 5 },
			method: 'get',
			title: {
				text: '',
				button: 'X'
			}
		},
		show: 'mouseover',
		hide: {
			fixed:true, 
			delay: 100,
			effect: {
				length: 100
			}
		},
		position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: {
				screen: true,
				y: 30,
				x: 20
			}
		},
		style: {
			width: 240,
			tip: {
				corner: 'bottomLeft',
				color: '#fff',
				size: {
					x:20,
					y:13
				}
			},
			border: {
				width: 0
			},
			title: { 'background': '#fff', 'position': 'absolute' },
			classes: {
				tooltip: 'artist'
			}
		},
		api: {
			beforeShow: renderCufon
		}
	});
	
	$('.1event a').qtip({
		content: {
			url: 'eventpopup.html',
			data: { id: 5 },
			method: 'get',
			title: {
				text: '',
				button: 'X'
			}
		},
		show: 'mouseover',
		hide: {
			fixed:true, 
			delay: 100,
			effect: {
				length: 100
			}
		},
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			},
			adjust: {
				screen: true,
				y: 0,
				x: 0
			}
		},
		style: {
			width: 350,
			tip: {
				corner: 'bottomLeft',
				color: '#fff',
				size: {
					x:13,
					y:20
				}
			},
			border: {
				width: 0
			},
			title: { 'background': '#fff', 'position': 'absolute' },
			classes: {
				tooltip: 'eventblue'
			}
		},
		api: {
			beforeShow: renderCufon
		}
	});
	
	$('#slideshow').cycle({
	    prev:   '#prev',
	    next:   '#next',
	    delay:  2000, 
		speed:  1500,
		random: 0
	});

});

$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
    $(pager).find('li').removeClass('activeLI')
        .filter('li:eq('+currSlideIndex+')').addClass('activeLI');
};

