$(function(){
	// Image Hover for Performers Page
	var offsetX = 20;
	var offsetY = 10;
	$('.omg_hover').hover(function(e){
		var imglink = $(this).attr('src');
		$('<img id="omgLargeImage" src="' + imglink + '" />').css({'top': e.pageY + offsetY, 'left': e.pageX + offsetX}).appendTo('body');
	}, function(){
		$('#omgLargeImage').remove();
	});
	
	$('.omg_hover').mousemove(function(e){
		$('#omgLargeImage').css({'top': e.pageY + offsetY, 'left': e.pageX + offsetX});
	});
	
	$('#eventtickethover').hover(function(e){
		var imglink = $(this).attr('src');
		$('<img id="omgLargeImage" src="' + imglink + '" />').css({'top': e.pageY + offsetY, 'left': e.pageX + offsetX}).appendTo('body');
	}, function(){
		$('#omgLargeImage').remove();
	});
	
	$('#eventtickethover').mousemove(function(e){
		$('#omgLargeImage').css({'top': e.pageY + offsetY, 'left': e.pageX + offsetX});
	});
	
	// Performer Monthly Hide/Show Section
	$('.show_monthevents').click(function(){
		$(this).parent().next('ul').slideToggle(750);
	});
	
	// Performer Monthly Hide/Show Section
	$('.sidenav_section_extended .eventbox_holder').click(function(){
		$(this).next('ul').slideToggle(750);
	});
	
	//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
	$('.table_style thead tr').addClass('tdrowstylewhite');
	//$('.add_to_cart, .uistyle').button();
	$('#quantity_filter').buttonset();
	
	var price_max = $('#price_slider').attr('max');
	var price_min = $('#price_slider').attr('min');
	
	var price_max_def = price_max;
	var price_min_def = price_min_def;
	
	var ticketoptions_form = $('#ticket_options');
	var ticketoptions_url = ticketoptions_form.attr('action');

	$('#price_slider').slider({
		range: true,
		min: parseInt(price_min),
		max: parseInt(price_max),
		step: 1,
		values: [parseInt(price_min), parseInt(price_max)],
		slide: function(e, ui) {
			$('#price_slider_range').val('$' + ui.values[0] + ' - $' + ui.values[1]);
			$('#min_price').val(ui.values[0]);
			$('#max_price').val(ui.values[1]);
		},
		stop: function(e, ui) {
			$('#tickets_available').fadeTo(250, '.25', function(){
				$('#loader').show();
			});
			$.ajax({
				url: ticketoptions_url,
				type: 'post',
				data: ticketoptions_form.serialize(),
				success: function(r){
					var rdata = $('#tickets_available tbody > *', r);
					$('#tickets_available tbody').html(rdata);
					//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
					$('.add_to_cart, .uistyle').button();
					$('#quantity_filter').buttonset();
					$('#loader').hide();
					$('#tickets_available').fadeTo(250, '1');
				}
			});
		}
	});
	
	$('#select_section').change(function(){
		$('#tickets_available').fadeTo(250, '.25', function(){
			$('#loader').show();
		});
		$.ajax({
			url: ticketoptions_url,
			type: 'post',
			data: ticketoptions_form.serialize(),
			success: function(r){
				var rdata = $('#tickets_available tbody > *', r);
				$('#tickets_available tbody').html(rdata);
				//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
				$('.add_to_cart, .uistyle').button();
				$('#quantity_filter').buttonset();
				$('#loader').hide();
				$('#tickets_available').fadeTo(250, '1');
			}
		});
	});
	
	$('#quantity_filter input').click(function(){
		$('#tickets_available').fadeTo(250, '.25', function(){
			$('#loader').show();
		});
		$.ajax({
			url: ticketoptions_url,
			type: 'post',
			data: ticketoptions_form.serialize(),
			success: function(r){
				var rdata = $('#tickets_available tbody > *', r);
				$('#tickets_available tbody').html(rdata);
				//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
				$('.add_to_cart, .uistyle').button();
				$('#quantity_filter').buttonset();
				$('#loader').hide();
				$('#tickets_available').fadeTo(250, '1');
			}
		});
	});
	
	$('#reset_options').click(function(){
		
		$('.ui-slider-handle:eq(0)', '#price_slider').css('left', '0%');
		$('.ui-slider-handle:eq(1)', '#price_slider').css('left', '100%');
		$('.ui-slider-range', '#price_slider').css({'left': 0, 'width': '100%'});
		
		$('#tickets_available').fadeTo(250, '.25', function(){
			$('#loader').show();
			$.ajax({
				url: ticketoptions_url,
				type: 'post',
				data: ticketoptions_form.serialize(),
				success: function(r){
					var rdata = $('#tickets_available tbody > *', r);
					$('#tickets_available tbody').html(rdata);
					//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
					$('.add_to_cart, .uistyle').button();
					$('#quantity_filter').buttonset();
					$('#loader').hide();
					$('#tickets_available').fadeTo(250, '1');
				}
			});
		});
		
	});
	
	$('.goto_month select').change(function(e) {
		var newURL = $(this).val();
		var Perf = $('.goto_month').attr('rel');
		$('.goto_month').attr('action', 'performer-events/'+Perf+'/by-month/'+newURL);
	});
	
	$('.sort_link').click(function(){
		var sort = $(this).attr('sort');
		var by = $(this).attr('by');
		$('.sort_link img').attr('src', 'skins/Default/images/arrow_right.png');
		if(by == 'asc')
			{
			$(this).attr('by', 'desc');
			$('img', this).attr('src', 'skins/Default/images/arrow_down.png');
			
			}
		else
			{
			$(this).attr('by', 'asc');
			$('img', this).attr('src', 'skins/Default/images/arrow_up.png');
			}
		$('#loader').show();
		$.ajax({
			url: ticketoptions_url,
			type: 'post',
			data: 'sort_section=' + sort + '&by=' + by,
			success: function(r){
				var rdata = $('#tickets_available tbody > *', r);
				$('#tickets_available tbody').html(rdata);
				//$('.table_style tbody tr:odd').addClass('tdrowstylewhite');
				$('.add_to_cart, .uistyle').button();
				$('#quantity_filter').buttonset();
				$('#loader').hide();
				$('#tickets_available').fadeTo(250, '1');
			}
		});
	});
	
	var hovertime;
	
	$('.mainnav > ul > li').hover(function(){
		clearTimeout(hovertime);
		$('.mainnav > ul > li').css('background-image', 'none');
		$(this).css('background-image', 'url(skins/Default/images/sitesprite.png)').css('background-repeat', 'repeat-x').css('background-position', 'left -628px');
		$('.maindropdown').hide();
		$('.maindropdown', this).show();
	}, function(){
		clearTimeout(hovertime);
		hovertime = setTimeout(function() {
			$('.maindropdown').hide();
			$('.mainnav > ul > li').css('background-image', 'none');
		}, 1000);
		if($('.maindropdown', this).css('display') != 'block')
			$('.mainnav > ul > li').css('background-image', 'none');
	});
	
	$('.maindropdown').hover(function(){
		clearTimeout(hovertime);
	}, function(){
		hovertime = setTimeout(function() {
			$('.maindropdown').hide();
			$('.mainnav > ul > li').css('background-image', 'none');
		}, 1000);

	});
	
	//$('.maindropdown_listsec > ul > li').hover(function() {
	//	$(this).css('background-position', '-872px -200px');
	//}, function() {
	//	$(this).css('background-position', '-894px -209px');
	//});
	
	$('.maindropdown_closebtn a').click(function(e) {
		e.preventDefault();
		$('.maindropdown').slideUp();
		$('.maindropdown').hide();
		$('.mainnav > ul > li').css('background-image', 'none');

	});
	
	$('.menu_search_concerts .dropdownsearch_text').focus(function(){
		if($(this).val() == 'Type what you are searching for...')
			$(this).val('');
	});
	
	$('.menu_search_concerts .dropdownsearch_text').blur(function(){
		string = jQuery.trim($(this).val());
		if(string.length == 0)
			$(this).val('Type what you are searching for...')
	});
	
	$('.menu_search_sports .dropdownsearch_text').focus(function(){
		if($(this).val() == 'Type what you are searching for...')
			$(this).val('');
	});
	
	$('.menu_search_sports .dropdownsearch_text').blur(function(){
		string = jQuery.trim($(this).val());
		if(string.length == 0)
			$(this).val('Type what you are searching for...')
	});
	
	$('.menu_search_theatre .dropdownsearch_text').focus(function(){
		if($(this).val() == 'Type what you are searching for...')
			$(this).val('');
	});
	
	$('.menu_search_theatre .dropdownsearch_text').blur(function(){
		string = jQuery.trim($(this).val());
		if(string.length == 0)
			$(this).val('Type what you are searching for...')
	});
	
	$('.menu_search_comedy .dropdownsearch_text').focus(function(){
		if($(this).val() == 'Type what you are searching for...')
			$(this).val('');
	});
	
	$('.menu_search_comedy .dropdownsearch_text').blur(function(){
		string = jQuery.trim($(this).val());
		if(string.length == 0)
			$(this).val('Type what you are searching for...')
	});
	
	$('.menu_search_pop .dropdownsearch_text').focus(function(){
		if($(this).val() == 'Type what you are searching for...')
			$(this).val('');
	});
	
	$('.menu_search_pop .dropdownsearch_text').blur(function(){
		string = jQuery.trim($(this).val());
		if(string.length == 0)
			$(this).val('Type what you are searching for...')
	});
	
	$('#get_email_form').submit(function(e){
		
		e.preventDefault();
		var flink = 'ajax_files/getemailform.ajax.php';
		var fdata = $(this).serialize();
		
		var email = $('input[name=email_addy]', this).val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if(reg.test(email) == false) {
			alert('Please insert a valid email address.');
			return false;
		}
		
		$.ajax({
			url: flink,
			type: 'post',
			data: fdata,
			success: function(r){
				$('.notickets_left > .performer_border_cont').html(r);
			}
		});
		
	});
	
	var string;
	
	$('#search_menu').submit(function(e){
		
		string = jQuery.trim($('.searchbar').val());
		
		if(string.length <= 1)
			e.preventDefault();

	});
	
	$('.menu_search_pop').submit(function(e){
	
		string = jQuery.trim($('.dropdownsearch_text', this).val());
		
		if(string.length <= 1 || string == 'Type what you are searching for...')
			e.preventDefault();

	});
	
	$('.menu_search_concerts').submit(function(e){
	
		string = jQuery.trim($('.dropdownsearch_text', this).val());
		
		if(string.length <= 1 || string == 'Type what you are searching for...')
			e.preventDefault();

	});
	
	$('.menu_search_sports').submit(function(e){
	
		string = jQuery.trim($('.dropdownsearch_text', this).val());
		
		if(string.length <= 1 || string == 'Type what you are searching for...')
			e.preventDefault();

	});
	
	$('.menu_search_theatre').submit(function(e){
	
		string = jQuery.trim($('.dropdownsearch_text', this).val());
		
		if(string.length <= 1 || string == 'Type what you are searching for...')
			e.preventDefault();

	});
	
	$('.menu_search_comedy').submit(function(e){
	
		string = jQuery.trim($('.dropdownsearch_text', this).val());
		
		if(string.length <= 1 || string == 'Type what you are searching for...')
			e.preventDefault();

	});
	
	$('.search_venue_holder').live('click', function(){
		if($('.holder_disp', this).css('display') == 'block')
			$('.holder_disp', this).hide('fast');
		else {
			$('.holder_disp', this).show('fast');
			$('.search_city_holder .holder_disp').hide();
		}
	});
	
	$('.search_city_holder').live('click', function(){
		if($('.holder_disp', this).css('display') == 'block')
			$('.holder_disp', this).hide('fast');
		else {
			$('.holder_disp', this).show('fast');
			$('.search_venue_holder .holder_disp').hide();
		}
	});
	
	var dates = $( "#from, #to" ).datepicker({
		minDate: 0,
		onSelect: function( selectedDate ) {
			var option = this.id == "from" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
	
	//$('.searchcal_textbtn').click(function(e){
	//	e.preventDefault();
	//	var dates = $( "#from" ).datepicker({
	//		mindDate: 0,
	//		onSelect: function( selectedDate ) {
	//			var option = this.id == "from" ? "minDate" : "maxDate",
	//				instance = $( this ).data( "datepicker" ),
	//				date = $.datepicker.parseDate(
	//					instance.settings.dateFormat ||
	//					$.datepicker._defaults.dateFormat,
	//					selectedDate, instance.settings );
	//			dates.not( this ).datepicker( "option", option, date );
	//		}
	//	});
	//});
	//
	//$('.searchcal_textbtn2').click(function(e){
	//	e.preventDefault();
	//	var dates = $( "#to" ).datepicker({
	//		mindDate: 0,
	//		onSelect: function( selectedDate ) {
	//			var option = this.id == "from" ? "minDate" : "maxDate",
	//				instance = $( this ).data( "datepicker" ),
	//				date = $.datepicker.parseDate(
	//					instance.settings.dateFormat ||
	//					$.datepicker._defaults.dateFormat,
	//					selectedDate, instance.settings );
	//			dates.not( this ).datepicker( "option", option, date );
	//		}
	//	});
	//});
	
	$('.searchcal_key').keypress(function(){
		if($(this).val() == 'Keyword:')
			$(this).val('');
	});
	
	$('.searchcal_location').keypress(function(){
		if($(this).val() == 'City:')
			$(this).val('');
	});
	
	$('.searchcal_venue').keypress(function(){
		if($(this).val() == 'Venue:')
			$(this).val('');
	});
	
	$('searchcal_key').blur(function(){
		if($(this).val().length == 0)
			$(this).val('Keyword:')
	});
	
	$('searchcal_location').blur(function(){
		if($(this).val().length == 0)
			$(this).val('City:')
	});
	
	$('searchcal_venue').blur(function(){
		if($(this).val.length == 0)
			$(this).val('Venue:')
	});
	
	$('.zip_input').keypress(function(){
		$(this).css('color', 'black');
		if($(this).val() == 'Enter City')
			$(this).val('');
	})
	
	$('.zip_input').live('keypress', function(){
		$(this).css('color', 'black');
		if($(this).val() == 'Enter City')
			$(this).val('');
	})
	
	$('#zip_search').submit(function(e) {
		e.preventDefault();
		searchcity = $('.zip_input').val();
		if(searchcity.search(/[a-zA-Z0-9]+,( |)[a-zA-Z]{2}/) == -1) {
			$('.zip_input').css('color', 'red');
		} else {
			$.cookie("SMOKING_CITY", searchcity, { expires: 365, path: '/' });
			window.location.reload(true);
		}
	})
	
	$('.eventticket_section_top small').click(function(e){
		e.preventDefault();
		$('.change_area_box h2').html('Local Events Settings');
		$('.eventticket_section_top').hide();
		$('.change_area_box').show();
		$('.local_events_zip').show();
		$('.noziptext').html('To display the local events and available tickets in your area, please enter your city name and state in the empty field below (e.g. City, State).').css('color', 'black');
	});
	
	$('.eventticket_section_top small').live('click', function(e){
		e.preventDefault();
		$('.change_area_box h2').html('Local Events Settings');
		$('.eventticket_section_top').hide();
		$('.change_area_box').show();
		$('.local_events_zip').show();
		$('.noziptext').html('To display the local events and available tickets in your area, please enter your city name and state in the empty field below (e.g. City, State).').css('color', 'black');
	});
	
	$('.headerright p a').click(function(e){
		e.preventDefault();
		$('.change_city').show();
		$('.headerright h3').css('padding-top', '10px');
		$(this).hide();
	});
	
	var newcity;
	
	$('.changecity_text').click(function() {
		$(this).css('color', 'black');
		if($(this).val() == 'City, State') {
			$(this).val('');
		}
	})
	
	$('#changecity_form').submit(function(e) {
		e.preventDefault();
		newcity = $('.changecity_text').val();
		if(newcity.search(/[a-zA-Z0-9]+,( |)[a-zA-Z]{2}/) == -1 || newcity == 'City, State') {
			$('.changecity_text').css('color', 'red');
		} else {
			$.cookie("SMOKING_CITY", newcity, { expires: 365, path: '/' });
			window.location.reload(true);
		}
	});
	
	$('#bookmark_btn').jBrowserBookmark();
	
	$('#contact_us_form').submit(function(e){
		e.preventDefault();
		var url = $(this).attr('action');
		var pdata = $(this).serialize();
		
		var flag = true;
		
		$('input[type=text], textarea', this).each(function(){
			if($(this).attr('name') != 'phone') {
				if($(this).val() == '') {
					flag = false;
					$(this).css('border', '1px solid red');
				} else
					$(this).css('border', '1px solid #666');
			}
		});
		
		if(flag == true) {
			$.ajax({
				url: 'ajax_files/contactus.php',
				data: pdata,
				type: 'post',
				success: function(r){
					$('html, body').animate({scrollTop: '0px'}, 500);
					if(r == 'SUCCESS') {
						$('.message.error').fadeOut(500);
						$('#contact_us_form').slideUp(500, function(){					
							$('.message.success').fadeIn(500);
						});
					} else {
						$('html, body').animate({scrollTop: '0px'}, 500);
						$('.message.error').fadeIn(500);
					}
				}
			});
		} else {
			$('html, body').animate({scrollTop: '0px'}, 500);
			$('.message.error').fadeIn(500);
		}
		
	});
	
	$('.user_address').click(function(){
		if($(this).val() == 'Enter Your Address')
			$('.user_address').val('');
	});
	
	$('.user_address').live('click', function(){
		if($(this).val() == 'Enter Your Address')
			$('.user_address').val('');
	});
	
	$('.showlocal_link, .showlocal_linktwo').click(function(e){
		e.preventDefault();
		$('.topeventsection').hide();
		$('.change_area_box').show();
	});
	
	$('#email_btn').click(function(e){
		e.preventDefault();
		$().interstitial('open', {
			'url' : 'ajax_files/email_page.php'
		});
	});
	
	$('#emailpage_form').live('submit', function(e){
		e.preventDefault();
		var email = $('#emailform_text').val();
		var page = document.location.href;
		if(email.search(/\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/gi) != -1) {
			$.ajax({
				url: 'ajax_files/email_pagep.php',
				data: 'email=' + email + '&page=' + page,
				type: 'post',
				success: function(r) {
					$('.ep_form').remove();
					$('#emailpage_form p').text('Thanks for sharing this page.');
				}
			});
		}
	});
	
	$('.ep_close').live('click', function() {
		$().interstitial('close', {});	
	});
	
	$('.le_price').each(function(){
	     var pricetd = $(this);
	     var relid = $(this).attr('rel');
	     $.ajax({
		  url: 'ajax_files/get_ticketprices2.php',
		  type: 'get',
		  data: 'id=' + relid,
		  success: function(s){
		       if(s == 'Sold Out') {
			    $(pricetd).parent().remove();
			    if($('.le_table tr').length == 2)
				$('.le_th').remove();
		       } else  
			    $(pricetd).html(s);
		  }
	     });
	     
	});
	
	$('.review_section_rating').hover(function() {
		$('.tix').hover(function() {
			$('.tix').attr('src', 'skins/Default/images/ticket2.png');
			var numRating = $(this).attr('rel');
			$('.tix').each(function() {
				if($(this).attr('rel') <= numRating)
					$(this).attr('src', 'skins/Default/images/ticket3.png');
			});
		});
	}, function() {
		$('.tix').attr('src', 'skins/Default/images/ticket2.png');
		var numRating = $('#ratingnum').val();
		$('.tix').each(function() {
			if($(this).attr('rel') <= numRating)
				$(this).attr('src', 'skins/Default/images/ticket1.png');
		});
	});
	
	$('.tix').click(function() {
		$('#ratingnum').val($(this).attr('rel'));
	});
	
	$('#leavereview').submit(function(e) {
		e.preventDefault();
		$('.nofill, .nocap').hide();
		if($('#ratingnum').val() == '' || $('#recaptcha_response_field').val() == '')
			$('.nofill').show();
		else {
			var reviewdata = $(this).serialize();
			var perfID = $('#reviewid').val();
			$.ajax({
				url: 'ajax_files/captcha.php',
				type: 'post',
				data: reviewdata,
				success: function(r) {
					if(r == 1) {
						$.ajax({
							url: 'ajax_files/sendreview.php',
							type: 'post',
							data: reviewdata,
							success: function(r) {
								$.cookie(perfID+'REVIEW', 1, { expires: 1 });
								$('.review_senthide').hide('slow').fadeOut(300);
								$('.review_sentshow').show('slow');
								$('.showreviewform').text('Review Submitted');
								$('.review_sent').attr('rel', 1);
							}
						});
					} else {
						$('.nocap').show();
						Recaptcha.reload();
					}
				}
			});
		}
	});
	
	$('.showreviewform').click(function() {
		if($('.review_sent').attr('rel') == '0') {
			if($('.review_senthide').css('display') == 'none')
				$('.review_senthide').show();
			else
				$('.review_senthide').hide();
		}
	});
	
});

function get_ticketprices() {
	
	$('.event_row_price').each(function(){
	     var pricetd = $('p', this);
	     var relid = $(this).attr('rel');
	     $.ajax({
		  url: 'ajax_files/get_ticketprices.php',
		  type: 'get',
		  data: 'id=' + relid,
		  success: function(s){
		       if(s == 'Sold Out')
			    $(pricetd).html('Coming Soon');
		       else  
			    $(pricetd).html(s);
			$(pricetd).show();
		  }
	     });
	     
	});

}

function initialize() {
	
	var lat = $('#map_canvas').attr('lat');
	var lon = $('#map_canvas').attr('lon');
	
	var myLatlng = new google.maps.LatLng(lat, lon);
	var windUrl = String(window.location);
	
	if(windUrl.search('event-tickets') == -1) {
		var myOptions = {
		  zoom: 9,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
	} else {
		var myOptions = {
		  zoom: 12,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
	}
	
	var map = new google.maps.Map(document.getElementById("map_canvas"),
		myOptions);
	
	if(windUrl.search('event-tickets') == -1) {
		var marker = new google.maps.Marker({
		    position: myLatlng, 
		    map: map, 
		    title:"City Center",
		    icon: 'http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png'
		});
	}
	
	var markadd;
	var geocoder;
	var stadium;
	var locstring;
	var resloc;
	var infoBox;
	
	$('.locevent_map').each(function(k){
		geocoder = new google.maps.Geocoder();
		
		markadd = $(this).attr('rel');
		
		geocoder.geocode({
			'address': markadd	
		}, function(results, status) {
			var marker = new google.maps.Marker({
				position: results[0].geometry.location,
				map: map,
				title: $('.locevent_map:eq('+k+')').attr('relname')
			});
		});
		
	});
	
	$('.direction_form').click(function(e){
		e.preventDefault();
		var parent = $(this).parent().parent();
		if($('.get_directions', parent).is(':hidden'))
			$('.get_directions', parent).show('slow');
		else
			$('.get_directions', parent).hide('slow');
	});
	
}

function initialize2() {
	
	var directionDisplay = new google.maps.DirectionsRenderer();
	var directionsService = new google.maps.DirectionsService();
	var map;
	
	var lat = $('#map_canvas_lg').attr('lat');
	var lon = $('#map_canvas_lg').attr('lon');
	
	var myLatlng = new google.maps.LatLng(lat, lon);
	var myOptions = {
	  zoom: 10,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map_canvas_lg"),
		myOptions);
	directionDisplay.setMap(map);
	directionDisplay.setPanel(document.getElementById("local_directions"));
		
	if($('#local_directions').attr('relstart') != '') {
		var start = $('#local_directions').attr('rel');		
		var end = $('#local_directions').attr('relstart');
		
		var request = {
			origin:start, 
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		
		directionsService.route(request, function(result, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionDisplay.setDirections(result);
			}
		});
		
		
	} else {
		
		var marker = new google.maps.Marker({
		    position: myLatlng, 
		    map: map, 
		    title:"City Center",
		    icon: 'http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png'
		});
		
		$('.locevent_map').each(function(k){
			geocoder = new google.maps.Geocoder();
			
			markadd = $(this).attr('rel');
			
			geocoder.geocode({
				'address': markadd	
			}, function(results, status) {
				if(results !== null) {
					var marker = new google.maps.Marker({
						position: results[0].geometry.location,
						map: map,
						title: $('.locevent_map:eq('+k+')').attr('relname')
					});
				}
			});
		});
	}
	
	var markadd;
	var geocoder;
	var locname;
	var locstring;
	
	
	$('.direction_form').click(function(e){
		e.preventDefault();
		var parent = $(this).parent().parent();
		if($('.get_directions', parent).is(':hidden'))
			$('.get_directions', parent).show('slow');
		else
			$('.get_directions', parent).hide('slow');
	});
	
	$('#change_start').click(function(e){
		e.preventDefault();
		var parent = $(this).parent().parent();
		$('.get_directions', parent).show('slow');
	});
	
	$('#city_link').click(function(e){
		e.preventDefault();
		$('html').scrollTop(1020);
	});
	
	$('.show_directions').click(function() {
		var shown = $(this).attr('is_shown');
		if(shown == '0') {
			$('#local_directions').show('slow');
			$(this).attr('is_shown', '1');
			$(this).text('Hide Directions');
		}
		else {
			$('#local_directions').hide('slow');
			$(this).attr('is_shown', '0');
			$(this).text('View Directions');
		}
	});
	
}


$(function(){
    
    var url = window.location.pathname;
    var name = '';
    var city = '';
    var venue = '';
    var from = '';
    var to = '';
    var curr = '';
    var tot = '';
    
    if($('#ajax_loader_img').attr('rel_name') != '' && $('#ajax_loader_img').attr('rel_name') != 'Performer')
         var name = $('#ajax_loader_img').attr('rel_name');
    else
         var name = '';
         
    if($('#ajax_loader_img').attr('rel_city') != '' && $('#ajax_loader_img').attr('rel_name') != 'City')
         var city = $('#ajax_loader_img').attr('rel_city');
    else
         var city = '';
         
    if($('#ajax_loader_img').attr('rel_venue') != '' && $('#ajax_loader_img').attr('rel_venue') != 'Venue')
         var venue = $('#ajax_loader_img').attr('rel_venue');
    else
         var venue = '';
         
    if($('#ajax_loader_img').attr('rel_from') != '' && $('#ajax_loader_img').attr('rel_from') != 'From')
         var from = $('#ajax_loader_img').attr('rel_from');
    else
         var from = '';
         
    if($('#ajax_loader_img').attr('rel_to') != '' && $('#ajax_loader_img').attr('rel_to') != 'To')
         var to = $('#ajax_loader_img').attr('rel_to');
    else
         var to = '';
         
	$('#event_finder').submit(function(e){
         
         if(($('.searchcal_key').val() == '' && $('.searchcal_location').val() == '' && $('.searchcal_venue').val() == '') || ($('.searchcal_key').val() == 'Keyword:' && $('.searchcal_location').val() == 'City:' && $('.searchcal_venue').val() == 'Venue:'))
              e.preventDefault();
         else {
              if($('.searchcal_key').val() == 'Keyword:')
                   $('.searchcal_key').val('');
              if($('.searchcal_location').val() == 'City:')
                   $('.searchcal_location').val('');
              if($('.searchcal_venue').val() == 'Venue:')
                   $('.searchcal_venue').val('');
              if($('.searchcaldate_input').val() == 'From:' || $('.searchcaldate_input').val() == '12/31/69')
                   $('.searchcaldate_input').val('');
              if($('.searchcaldate_input2').val() == 'To:' || $('.searchcaldate_input2').val() == '12/31/69')
                   $('.searchcaldate_input2').val('');
              
              name = jQuery.trim($('.searchcal_key').val());
              city = jQuery.trim($('.searchcal_location').val());
              venue = jQuery.trim($('.searchcal_venue').val());
         
              from = jQuery.trim($('.searchcaldate_input').val());
              to = jQuery.trim($('.searchcaldate_input2').val());
         }
         
	});
    
    var numRows;

    if(url == '/search/' || url == '/smokingtickets.com/search/') {
         $.ajax({
              url: url,
              type: 'get',
              data: '&active=1&name=' + name + '&city=' + city + '&venue=' + venue + '&from=' + from + '&to=' + to,
              success: function(r){
                   curr = $('#rowcheck', r).attr('rel_curr');
                   tot = $('#rowcheck', r).attr('rel_tot');
                   if($('#search_results', r).html() == '' || $('#search_results', r).text() == '') {
                        if(name == '') { name = 'Any Performer'}
                        if(city == '') { city = 'Any City'}
                        if(venue == '') { venue = 'Any Venue'}
                        $('#search_results').html('<tr><td style="border-bottom: none;">There were no results found for: <font color="#ff0000">' + name + '</font> at <font color="#ff0000">' + venue + '</font> in <font color="#ff0000">' + city + '</font>. <br/>Please try your search again, and make sure you are using the correct search combinations.</td></tr>');
						$('#exact_results').hide();
				   }
                   else {
                        $('#search_results').html($('#search_results', r).html());
						if($('#exact_results tr', r).length > 1) {
							$('#exact_holder').show()
							$('#exact_results').html($('#exact_results', r).html());
							$('#exact_holder h3').text(name + ' Tickets and Events');
							var url = $('#exact_results .search_header th:eq(0)').attr('rel');
							$('#exact_holder span').html('<a href="performer-events/'+url+'-tickets">View All ' + name + ' Tickets and Scheduled Events</a><br /><a href="performer-events/'+url+'-tickets/videos">View ' + name + ' Videos</a>');
							$('#exact_results').after('<div class="botlink_holdertwo"><h3>See below for other related search results:</h3></div>');
							$('#exact_results').after('<div class="botlink_holder"><a class="exact_botlink" href="performer-events/'+url+'-tickets">View All ' + name + ' Events</a></div>');
						}
                   }
                   
                   $('#ajax_loader_img').hide();
                   
                   var count = $('.search_name_holder p', r).length - 2;
                   
                   if(count > 1)
                        $('.search_name_holder').html($('.search_name_holder', r).html());
                   else
                        $('.search_name_holder').hide();
                        
                   if($('.see_more_res', r).html() != '' || $('.see_more_res', r).text() != '') {
                        $('.see_more_res').html($('.see_more_res', r).html());
                   }
                   
                   $('.search_venue_holder').html($('.search_venue_holder', r).html());
                   $('.search_city_holder').html($('.search_city_holder', r).html());
                        
                   $('.search_res_row').each(function(){
                        var pricetd = $('#search_next_last', this);
                        var relid = $(this).attr('rel');
                        $.ajax({
                             url: 'ajax_files/get_ticketprices.php',
                             type: 'get',
                             data: 'id=' + relid,
                             success: function(s){
                                  if(s == 'Sold Out')
                                       $(pricetd).parent('tr').remove();
                                  else     
                                       $(pricetd).html(s);
                                  numRows = $('#search_results tr').length;
                                  if(numRows == 1) {
                                       if(name == '') { name = 'Any Performer'}
                                       if(city == '') { city = 'Any City'}
                                       if(venue == '') { venue = 'Any Venue'}
                                       $('.search_city_holder').remove();
                                       $('.search_venue_holder').remove();
                                       $('#search_results').html('<tr><td style="border-bottom: none;">There were no available tickets found for: <font color="#ff0000">' + name + '</font> at <font color="#ff0000">' + venue + '</font> in <font color="#ff0000">' + city + '</font>. <br/>Please try your search again, and make sure you are using the correct search combinations.</td></tr>');
										$('#exact_holder').hide();
								  }
                             }
                        });
                        
                   });
                   
              }
         
         });
    }
	   
    $('.search_filter_name').live('click', function(e){
         e.preventDefault();          
         var name = $(this).text();
		 
         if(name == '| View All | ') {
              $('#search_results .search_res_row').show();
		 }
         else {
              $('#search_results .search_res_row').hide();
              $('#search_results .search_res_row[rel_name="' + name + '"]').show();
         }
         
    });
    
    $('.see_more_res a').live('click', function(e){
         e.preventDefault();
         
         var div = $(this);
         
         $('#ajax_loader_img').insertAfter($('#search_results'));
         $('#ajax_loader_img').show();
         div.hide();
         
         $.ajax({
                  url: url,
                  type: 'get',
                  data: '&active=1&name=' + name + '&city=' + city + '&venue=' + venue + '&from=' + from + '&to=' + to + '&curr=' + curr,
                  success: function(r){
                       curr = $('#rowcheck', r).attr('rel_curr');
                       
                       $('#ajax_loader_img').hide();
                       div.show();
                       
                       if(parseInt(curr) > parseInt(tot)) {
                             $('.see_more_res').hide();
                       }
                   
                       if($('#search_results', r).html() == '' || $('#search_results', r).text() == '') {
                       }
                       else {
                             var ressearch = $('#search_results', r).html();
                             $('#search_results').append(ressearch);
                       }
                       
                       //var count = $('.search_name_holder p', r).length - 2;
                       //
                       //if(count > 1)
                       //     $('.search_name_holder').html($('.search_name_holder', r).html());
                       //else
                       //     $('.search_name_holder').hide();
                       //     
                       //if($('.see_more_res', r).html() != '' || $('.see_more_res', r).text() != '') {
                       //     $('.see_more_res').html($('.see_more_res', r).html());
                       //}
                       //
                       //$('.search_venue_holder').html($('.search_venue_holder', r).html());
                       //$('.search_city_holder').html($('.search_city_holder', r).html());
                            
                       $('.search_res_row').each(function(){
                            var pricetd = $('#search_next_last', this);
                            var relid = $(this).attr('rel');
                            $.ajax({
                                 url: 'ajax_files/get_ticketprices.php',
                                 type: 'get',
                                 data: 'id=' + relid,
                                 success: function(s){
                                      if(s == 'Sold Out')
                                           $(pricetd).parent('tr').remove();
                                      else     
                                           $(pricetd).html(s);
                                 }
                            });
                            
                       });
                       
                  }
             
             });
         
    });
    
    // Banner Rotate
    $('#rotate_bannerframe div#rotate_cont').cycle({
		fx: 'fade',
		timeout: 7000,
		delay:  -1000,
		after: onAfter,
		prev:   '#banner_prevlink', 
	    next:   '#banner_nextlink',
		pause: 1
	});
	
	function onAfter(curr,next,opts) {
		var url = $('div.rotate_bannercontent:eq('+opts.currSlide+') div.rotate_bannerimg a').attr('href');
		$('#silver_overlay a').attr('href', url);
	};
	
	$('#af_clist').change(function() {
		if($(this).val() == 'United States of America')
			$('.af_states').show();
		else
			$('.af_states').hide();
		var country = $(this).val();
		var caturl = $('.af_countries').attr('rel');
		$.ajax({
			url: 'ajax_files/arenalist.php',
			data: 'country='+country+'&caturl='+caturl,
			type: 'get',
			success: function(r) {
				$('.arenalisting').html(r);
			}
		});
	});
    
	$('#af_slist').change(function() {
		var state = $(this).val();
		var country = $('#af_clist').val();
		var caturl = $('.af_countries').attr('rel');
		$.ajax({
			url: 'ajax_files/arenalist.php',
			data: 'country='+country+'&caturl='+caturl+'&state='+state,
			type: 'get',
			success: function(r) {
				$('.arenalisting').html(r);
			}
		});
	});
	
	$('#view_more_vids').click(function(e){
		e.preventDefault();
		$('html, body').animate({scrollTop: $('div[rel=view_more_vids]').position().top+'px'}, 500);
	});
	
	var lastdiv
	var lastID;
	var pID;
	var newdiv;
	var scrollPos;
	var isSplash = 0;
	var ajaxLimit = 0;
	
	var windLoc = String(window.location);

	$(window).scroll(function() {
		if($('.vid_count_num').length > 0) {
			divPos = $('.vid_count_num').position();
			scrollPos = (divPos.top - 800);
			if($(window).scrollTop() >= (scrollPos)) {
				lastdiv = $('.vid_row').eq(-1);
				lastID = $('.vid_section').attr('rel');
				lastVid = $('.vid_count_num').attr('rel');
				isSplash = $('.vid_splash').attr('rel');
				pID = $('.vid_section').attr('pid');
				if(parseInt(lastID) < parseInt(lastVid)) {
					if(lastID != 'NOMORE' && ajaxLimit == 0) {
						ajaxLimit = 1;
						$('.vids_pacman').show();
						$('.vid_section').attr('rel', parseInt(lastID) + 1);
						$.ajax({
							url: 'ajax_files/loadmorevids.php',
							data: 'lastID=' + lastID + '&pID=' + pID + '&splash=' + isSplash,
							type: 'get',
							success: function(r) {
								lastdiv.after(r);
								$('.vids_pacman').hide();
								ajaxLimit = 0;
							}
						});
					} else if(lastID != 'NOMORE' && ajaxLimit == 1) {
						
					} else {
						$('.vids_pacman').hide();
					}
				}
			}
		}
	});
	
	$('.news_months li').click(function() {
		if($('.news_posts', this).css('display') == 'none') {
			$('.news_posts', this).show('slow');
		} else {
			$('.news_posts', this).hide('slow');
		}
	});
	
	$('.vid_radiobtn').click(function() {
		$('.vs_form').attr('action', 'search/videos/');
	});
   
	$('.tik_radiobtn').click(function() {
		$('.vs_form').attr('action', 'search/');
	});
	
	$('.hs_tik').click(function() {
		$('#search_menu').attr('action', 'search/');
	});
   
	$('.hs_vid').click(function() {
		$('#search_menu').attr('action', 'search/videos/');
	});
   
});
