
	jQuery(function($) {
		
		$('.obf').deObf();
												
		$('.pop[rel]').overlay({ 
			top: 'center', 
			mask: { 
				color: '#000', 
				loadSpeed: 200, 
				opacity: 0.66 
			}, 
			closeOnClick: false, 
			closeOnEsc: false,
			fixed: true
		});
								
		$('.hometabs > ul').tabs('.homepanes > .homepane', { 
			history: true,
			onClick: function() {
            	if($('#venues_map_canvas').length) $venues_map_initialize();
            	if($('#av_companies_map_canvas').length) $av_map_initialize();
            }
		});
					
		$('.faqul').tabs('.faqul > .faqpane', { tabs: '.faqtab', effect: 'slide', initialIndex: null });
				
		$(".note a[title]").tooltip();
				
		$('.faq-q a').live('click',function() {
			var whereto = $(this).attr('href');
			$('html, body').stop(true,true).animate({
				scrollTop: $(whereto).offset().top
			}, 500);
			return false;
		});
				
		$('.auto')
			.each(function() { if($(this).val() == '') { $(this).val($(this).attr('placeholder')).removeClass('active'); } })
			.focusin(function() { $(this).addClass('focused'); if($(this).val() == $(this).attr('placeholder')) { $(this).val('').addClass('active'); } })
			.focusout(function() { $(this).removeClass('focused'); if($(this).val() == '') { $(this).val($(this).attr('placeholder')).removeClass('active'); } });
			
		$('.auto-s').change(function() { 
			if($(this).val() == '') { $(this).removeClass('active'); } else { $(this).addClass('active'); }
		});
		
		$('form input').each(function() {
			if($(this).val() == $(this).attr('placeholder')) { $(this).removeClass('active'); } else { $(this).addClass('active'); }
		});
		
		$('form textarea').each(function() {
			if($(this).val() == $(this).attr('placeholder')) { $(this).removeClass('active'); } else { $(this).addClass('active'); }
		});
		
		$('form select').each(function() {
			if($(this).val() == '') { $(this).removeClass('active'); } else { $(this).addClass('active'); }
		});
		
		$('.dropche input[type=text]').click(function() {
			$(this).closest('.dropche').toggleClass('dropen');
		});
		
		$('.dropchediv input').click(function() {
			$eq = new Array();
			$(this).closest('.dropchediv').find('input').each(function() {
				if($(this).is(':checked')) $eq.push($(this).attr('alt'));
			});
			if($eq.length > 0) {
				$(this).closest('.dropche').find('input[type=text]').val($eq.join(', ')).addClass('active');
			}
			else {
				$(this).closest('.dropche').find('input[type=text]').val($(this).attr('placeholder')).removeClass('active');
			}
		});
		
		$('.dropche').outerClick(function() {
			$(this).closest('.dropche').removeClass('dropen');
		});
					
		$("input[name=event_start_date]").dateinput({
			min:-1,
			format:'mm/dd/yyyy',
			change: function() {
				$("input[name=event_end_date]").data("dateinput").setMin(this.getValue(), true);
				var d = this.getValue('mm/dd/yyyy');
				this.getInput().val(d);
			}
		});
		
		$("input[name=event_end_date]").dateinput({
			min:-1,
			format:'mm/dd/yyyy',
			change: function() {
				var d = this.getValue('mm/dd/yyyy');
				this.getInput().val(d);
			}
		});
		
		$("input[name=event_deadline]").dateinput({
			min:-1,
			format:'mm/dd/yyyy',
			change: function() {
				var d = this.getValue('mm/dd/yyyy');
				this.getInput().val(d);
			}
		});
		
		$('.popup .subscribe-button').live('click',function() {
					
			var data = $(this).closest('form').serialize(); 
						
			$.ajax({
  				url: 'ajax/subscribe',
  				type: 'POST',
  				cache: false,
  				data: data,
  				beforeSend: function() {
  					$('#signup-popup .rqloading').html('').removeClass('errors success').show();
  				},
  				success: function(data) {
  					if(data == '') {
  						$('#signup-popup .rqloading').removeClass('errors').html('');
  						$('#signup-popup .rqloading').addClass('success').html('<ul><li>Thank you. You\'re subscribed</ul></li>');
  					}
  					else {
  						$('#signup-popup .rqloading').removeClass('success').addClass('errors').html(data);
  					}
  				}
			});
			
			return false;
		});
		
		$('div.subscroll a').click(function() {
			var $anchor = $(this).attr('rel');
			$('.form_scrolling').scrollTo($anchor, 600, { 'easing': 'easeOutBack' });
			return false;
		});
		
		$('.updbu').click(function() {
			var $i = $(this).siblings('input');
			var $p = $i.attr('rel');
			var $v = $i.val();
			$('input[name="event_rental_needs[' + $p + '][quantity]"]').val($v);
			return false;
		});
		
		$('#sq3 .disabled').click(function() {
			return false;
		});
		
		$('.pricefield').blur(function() {
			$(this).toNumber().formatCurrency();
			$total = 0; 
			$('.pricefield:not(.totalpf)').each(function() {
				$total += $(this).asNumber(); 
			});
			$('.totalpf').val($total).formatCurrency();
		});
		
		if($('#qof').length) {
			$total = 0; 
			$('.pricefield:not(.totalpf)').each(function() {
				$total += $(this).asNumber(); 
			});
			$('.totalpf').val($total).formatCurrency();
		}
		
		$('#qof').submit(function(e) {
			$('.pricefield').each(function() { 
				$(this).toNumber().formatCurrency();
			});
			$total = 0; 
			$('.pricefield:not(.totalpf)').each(function() {
				$total += $(this).asNumber(); 
			});
			$('.totalpf').val($total).formatCurrency();
			$('#qof').submit();
		});
		
		$('#rqev').click(function() {
			var $c = new Array();
			$('.listing input:checked').each(function() { 
				$c.push($(this).val());
			});
			if($c.length > 0) {
				$('#rqfv').submit();
			}
			else {
				$('#rqevcall').click();
			}
			return false;
		});
		
		$('#rqeavc').click(function() {
			var $c = new Array();
			$('.listing input:checked').each(function() { 
				$c.push($(this).val());
			});
			if($c.length > 0) {
				$('#rqfav').submit();
			}
			else {
				$('#rqeavccall').click();
			}
			return false;
		});
		
		$('select[name=event_need_venue]').change(function() { 
			if($(this).val() == 'Yes') {
				$('.dropche').addClass('required');
			}
			else {
				$('.dropche').removeClass('required');
			}
		});
		
		var $hbd = 0;
		$('.hbd').each(function() {
			if ($(this).height() > $hbd) $hbd = $(this).height();
		});
		$('.hbd').height($hbd);
		
		$('input[name=event_phone_number]').phmask("999-999-9999");
		$('input[name=venue_contact_number]').phmask("999-999-9999");
		$('input[name=av_company_contact_number]').phmask("999-999-9999");
		
	});
	
	$.fn.deObf = function() {
   		return this.each(function(){
     		var email = $(this).text().replace(/\s*\(.+\)\s*/,"@");
     		$(this).text(email).rot13();
     		$(this).attr('href','mailto:' + $(this).text());
   		});
	}; 
	
	$.fn.rot13 = function() {
        this.each(function() {
            $(this).text($(this).text().replace(/[a-z]/ig, function(chr) {
                var cc = chr.charCodeAt(0);
                if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26);
                else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26);
                return String.fromCharCode(cc);
            }));
        });
        return this;
    };
