/**
 * Remap jQuery to $
 * incase $ has been over written by another framework
*/

( 
	function( $ )
	{
		/**
		 * on Document Ready
		*/
		
		$(document).ready(
			
			function()
			{
				if ( $('#buy-now-form').length )
				{
					$('#buy-now-form').submit(
						
						function()
						{
							
							var form = document.createElement("form");
							form.setAttribute("method", "post");
							form.setAttribute("action", $(this).attr('action'));

							// setting form target to a window named 'formresult'
							form.setAttribute("target", "formresult");
							
							var hiddenField = document.createElement("input");              
							hiddenField.setAttribute("name", "mode");
							hiddenField.setAttribute("value", "PayPlus");
							
							form.appendChild(hiddenField);
							
							var hiddenField = document.createElement("input");              
							hiddenField.setAttribute("name", "chargetotal");
							hiddenField.setAttribute("value", "1900.00");
							
							form.appendChild(hiddenField);
							
							var hiddenField = document.createElement("input");              
							hiddenField.setAttribute("name", "storename");
							hiddenField.setAttribute("value", "1001256051");
							
							form.appendChild(hiddenField);
							
							var hiddenField = document.createElement("input");              
							hiddenField.setAttribute("name", "txntype");
							hiddenField.setAttribute("value", "sale");
							
							form.appendChild(hiddenField);
							
							document.body.appendChild(form);

							// creating the 'formresult' window with custom features prior to submitting the form
							window.open( $(this).attr('action'), 'formresult', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

							form.submit();
							
							return false;
						}
					);
				}
				
				/* Scrolling Boxes */
				
				if ( $('.tubepress_thumbnail_area').length )
				{
					$('.tubepress_thumbnail_area').jScrollPane();
				}
				
				/* Fix contact form input as submit */
				
				$('form.wpcf7-form input.wpcf7-submit').remove();
				
				$('form.wpcf7-form').append( '<p><button class="wpcf7-button-submit" name="submit" value="send">Send</button>' );
				
				/* Signup page */
				
				if ( $('#tools-signup').length )
				{
					$('#tools-signup form input').each(
						
						function()
						{
							if ( $(this).val() == '' && $(this).attr('data-holder') != '' )
							{
								var text_holder = $(this).attr('data-holder');
								
								$(this).val(text_holder);
							}
						}
					).bind(
						
						{
							focus: function()
							{
								if ( $(this).val() == $(this).attr('data-holder') )
								{
									$(this).val('');
								}
							},
							
							blur: function()
							{
								if ( $(this).val() == '' )
								{
									$(this).val($(this).attr('data-holder'));
								}
							}
						}
						
					);
				}
				
				/* Tour Map */
				
				if ( $('#tour-map').length )
				{
					$('#tour-map-pins a, #tour-map-links a').bind(
						
						'click',
						
						function()
						{
							// hide all open popups
							$('#tour-map-pins .popup').hide();
							
							// show correct popup
							var show = $(this).attr('rel');
							
							$('#pin-' + show + ' .popup').fadeIn(600);
							
							return false;
						}
						
					);
					
					$('#tour-map-pins .popup a.close').bind(
						
						'click',
						
						function()
						{
							$(this).parent('div.popup').fadeOut(600);
						}
						
					);
				}
				
				/* Remove Items From The Dom */
				
				$('.rgba #default-loop .top, .rgba #default-loop .bottom').remove();
				
				/* Home Page Slider */
				
				if ( $('#slideshow').length )
				{
					$('#slideshow').nivoSlider(
						{
							pauseOnHover: false,
							pauseTime: 4500
						}
					);
				}
				
				
				
				/* Google Maps */
				/*
				var map = new GMap2($("#map").get(0));
				var burnsvilleMN = new GLatLng(44.797916,-93.278046);
				map.setCenter(burnsvilleMN, 8);
				
				// setup 10 random points
				var bounds = map.getBounds();
				var southWest = bounds.getSouthWest();
				var northEast = bounds.getNorthEast();
				var lngSpan = northEast.lng() - southWest.lng();
				var latSpan = northEast.lat() - southWest.lat();
				var markers = [];
				for (var i = 0; i < 10; i++) {
				    var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
				        southWest.lng() + lngSpan * Math.random());
					marker = new GMarker(point);
					map.addOverlay(marker);
					markers[i] = marker;
				}
				
				$(markers).each(function(i,marker){
					$("<li />")
						.html("Point "+i)
						.click(function(){
							displayPoint(marker, i);
						})
						.appendTo("#list");
					
					GEvent.addListener(marker, "click", function(){
						displayPoint(marker, i);
					});
				});
				
				$("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
				
				function displayPoint(marker, index){
					$("#message").hide();
					
					var moveEnd = GEvent.addListener(map, "moveend", function(){
						var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
						$("#message")
							.fadeIn()
							.css({ top:markerOffset.y, left:markerOffset.x });
					
						GEvent.removeListener(moveEnd);
					});
					map.panTo(marker.getLatLng());
				}
				*/
			}
			
		);
	}
	
) ( this.jQuery );
