/* Javascript Document Copyright 2006-2009 Andrei Gonzales. All Rights Reserved */
/* Version 1.0 */
/* Type: Javascript General Code Sheet for P and P Tattoo and Body Art */

$(document).ready(function(){
/***************************************
*** Common Misc JavaScript Functions ***
***************************************/
// Replace Submit buttons with anchors and Validate Forms
$('input[type=submit]').each(function(){		
	$(this).parents('form.cmxform').validate({
		highlight: function(element){
			$(element).addClass("errbar");
		},
		unhighlight: function(element){
			$(element).removeClass("errbar");
		},
		errorPlacement: function(error, element){
			error.appendTo(element.prev('.errorbox'));
		}
	});
	// Above error function is necessary for the last line below to work
	var formId = $(this).parents('form.cmxform').attr('id');
	var elId = $(this).attr('id');
	var elName = $(this).attr('name');
	var elClass = $(this).attr('class');
	var elTitle = $(this).attr('title');
	var nuText = $(this).val();
	$(this).after('<a id="'+elId+'1" name="'+elName+'1" class="'+elClass+'" title="'+elTitle+'" onclick="$(\'#'+formId+'\').trigger(\'submit\');">'+nuText+'</a>').remove();
});

/*** Tipbox hover ***/
	/* CONFIG */		
		xOffset = -15;
		yOffset = 5;		
		// These 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tipbox").hover(function(e){											  
		this.t = this.title;
		this.title = "";
		this.r = this.rel;
		this.rel ="";
		if (!this.r) {
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		} else {
			$("body").append("<p id='tooltip'><img src='"+ this.r +"'/>"+ this.t +"</p>");
			$("#tooltip img").css('display','block');
		};		
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;	
		this.rel = this.r;
		$("#tooltip").remove();
    });	
	$(".tipbox").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
	
/*** Input Field - Clearing Default Values ***/
var default_values = {};
	jQuery('input, textarea').each(function(i) {
    var index = jQuery(this).attr('name');
    var value = jQuery(this).val();
    default_values[index] = value;
  	});

  	jQuery('input, textarea').focus(function() {
    if(jQuery(this).val() === default_values[jQuery(this).attr('name')]) {
      jQuery(this).val('');
    };
});

/*** Googlemap Lightbox ***/
	$('a.popupvideo').removeAttr('href');
	$('a.popupvideo').attr('title','Clicking this link will not open a new window or tab in your browser');
	//clearmap.remove();
	$('a.popupvideo').click(function(){
		var h = $("#floor").height();
    	$('#facebox-dim')
			.height(h)
			.css({
				display:'block',
				opacity: '0.8'
				})
			.fadeIn();
		$('.biggiemap')
			.fadeIn()
			.css({
				display:'block'
				});
		});
	
	$('#facebox-dim').click(function(){		
		$('.biggiemap').fadeOut();
		$('#facebox-dim').fadeOut();
		});


/*** Adjust Flash Size According to Browser ***/
	var truH = $("#floor").height();
	var tester = $('#flashbg').height(truH);
	
/*** Bastard Browser (IE6) Hover Fixes ***/
//$("#mh-menu ul li").addClass('js-on');

	$("#main-menu ul li").hover(
	function(){
		$(this).addClass('wax-on');
	},
	function(){
		$(this).removeClass('wax-on');
	});

/*** Add Quotations to Block Quotes ***/
$('blockquote').each(function(){
 $(this).prepend('<span class="bq-quote-s">&nbsp;</span>');
 $(this).append('<span class="bq-quote-e">&nbsp;</span>')
})

/*** Contact Us Hover ***/
$('.page-item-15').hover(
	function(){
		$('li.mm-end').addClass('mm-end-active');
	},
	function(){
		$('li.mm-end:not(.current-page)').removeClass('mm-end-active');
});

/*** DD Menu Bottom-border Fix ***/
$('div#main-menu > ul > li > ul').find('li:last').css("border-bottom","0");
$('div#main-menu > ul > li > ul > li:last').css("border-bottom","0");

$.localScroll();

// End jQuery
});