$(document).ready(function(){

	// sIFR
		var myriad = {
			src: '/jiwire/flash/sifr_myriad-pro-semibold.swf',
			ratios: [6,1.41,9,1.35,15,1.29,21,1.25,22,1.22,27,1.24,29,1.21,34,1.22,41,1.21,45,1.2,46,1.21,59,1.2,68,1.19,69,1.2,96,1.19,97,1.18,102,1.19,103,1.18,107,1.19,108,1.18,112,1.19,114,1.18,116,1.19,120,1.18,121,1.19,1.18]
		};
		
		sIFR.prefetch({
			src: '/jiwire/flash/sifr_myriad-pro-semibold.swf'
		});
		
		sIFR.useDomContentLoaded = false;
		
		sIFR.useStyleCheck = true;
		sIFR.activate( myriad );
	
	
	// adding extra layer for IE (png transparency fix)
		$( "#shad-over, #shad-over-errors, #shad-over-hotspot-rating, #shad-over-rate-hotspot, #shad-over-register-hotspot, #shad-over-driving-directions, #shad-over-directions" ).append( '<div class="shad-over-inner"></div>' );
		
	// png transparency fix
		$.ifixpng('http://images.jiwire.com/images/v4/new/blank.gif');
		$('img[@src$=.png]').ifixpng();
		
	// show popup if it's not hidden by default
   		if ( $( "#shad-over" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over" );
		}
   		if ( $( "#shad-over-directions" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-directions" );
		}
		
   		if ( $( "#shad-over-rate-hotspot" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-rate-hotspot" );
		}
		
   		if ( $( "#shad-over-hotspot-rating" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-hotspot-rating" );
		}
		
   		if ( $( "#shad-over-register-hotspot" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-register-hotspot" );
		}
   		if ( $( "#shad-over-register-hotspot-step2" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-register-hotspot-step2" );
		}
   		if ( $( "#shad-over-driving-directions" ).attr( "class" ) != "hideitnow" )
		{
			showpopup( "#shad-over-driving-directions" );
		}
		
		$( "#footer .show-search a" ).bind( "click", function() {
																			
			showpopup( "#shad-over" );
			
			return false;
			
		});
								   
	// custom scrollbars
		$('div.scrolling').jScrollPane( {showArrows:true, scrollbarWidth: 9 } );
						   
	// navigation
		$( "#menu > li" ).bind( "mouseover", function() {
			$( this ).addClass( "active" );		
		});
		
		$( "#menu > li" ).bind( "mouseout", function() {		
			$( this ).removeClass( "active" );		
		});
		
	// serach filed
		$( ".search input" ).bind( "focus", function() {
			
			// set the color
				$( this ).css({ color: "#000000" });
			
			// clear the text if it's set to the default one
				if ( $( this ).attr( "value" ) == "Find Wi-Fi by city or zip..." )
					$( this ).attr({ value: "" });
		});
		
		$( ".search input" ).bind( "blur", function() {
			
			// set the color
				$( this ).css({ color: "#999999" });
			
			// set the default text if input's empty
			if ( $( this ).attr( "value" ) == "" || typeof( $( this ).attr( "value" ) ) == "undefined" )
				$( this ).attr({ value: "Find Wi-Fi by city or zip..." });
		});
	
	// rating
		if (document.getElementById("rate1")) {
			$('#rate1').rating( '#', { maxvalue: 5 } );		
			$('.rate-this-location .rating span a').bind( 'click', function() {
				$( this ).siblings().removeClass( 'highlight' );
				$( this ).addClass( 'highlight' );
				return false;
			});
		}
			
	// add sifr
		function addsIFR ( id ) {
				sIFR.replace( myriad, {
					selector: id+' div.box-top h2',
					css: [
						'.sIFR-root { font-weight: bold; color: #ffffff; }'
					],
					wmode: "transparent"
				});
		}
	
	// hidepopup
		function hidepopup (id) {
			//  load the detail map after closing driving directions
			    if(id=="#shad-over-driving-directions"){
			        loadMap();
			    }
			// classes manipulation
				$( id ).removeClass( "showitnow" );
				$( id ).addClass( "hideitnow" );
			
		}
	// end of hidepopup
	
	// showpopup
		function showpopup (id) {
			
			// classes manipulation			
				$( id ).removeClass( "hideitnow" );
				$( id ).addClass( "showitnow" );
				
				addsIFR ( id );			
		}
	// end of showpopup
	
   
   // do not show all the popups by default
	//showpopup();
	
	// close button in popups
		$( "#shad-over .box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over");
	
			// do not relocate to "#"
				return false;
		
		});
	// end of close button in popups

	// close button in popups
		$( "div.showitnow div.box-top a.close, #shad-over-directions div.box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-directions");
	
			// do not relocate to "#"
				return false;
		
		});
	// end of close button in popups

	// close button in popups
		$( "#shad-over-register-hotspot div.box-top a.close div.box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-register-hotspot");
	
			// do not relocate to "#"
				return false;
		
		});

		$( "#shad-over-register-hotspot-step2 div.box-top a.close div.box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-register-hotspot-step2");
	
			// do not relocate to "#"
				return false;
		
		});
	// end of close button in popups

	// register a new wifi location popup
		$( "#side-rate-hotspot, #paging-rate-hotspot" ).bind( "click", function() {
		
			// show #shad-over
				showpopup("#shad-over-rate-hotspot");
				
			// do not relocate to "#"
				return false;
		
		});
	// end of register a new wifi location popup


	// register a new wifi location popup
		$( "#side-register-new" ).bind( "click", function() {
		
			// show #shad-over
				showpopup("#shad-over-register-hotspot");
				
			// do not relocate to "#"
				return false;
		
		});
		$( "#side-register-new-step2" ).bind( "click", function() {
		
			// show #shad-over
				showpopup("#shad-over-register-hotspot-step2");
				
			// do not relocate to "#"
				return false;
		
		});
	// end of register a new wifi location popup
	
	// unhide div when clicking close for #shad-over
	$("#shad-over .box-top .close").bind( "click", function() {
		$("#h3ad").show();
		$("#add-flash-map").show();
	});
	

	// search a new wifi location popup
		$( "#side-search-new" ).bind( "click", function() {
			// hide #add-flash-map
				$("#add-flash-map").hide();
		
			// show #shad-over
				showpopup("#shad-over");
				
			// do not relocate to "#"
				return false;
		
		});
	// end of search a new wifi location popup	

	// search a new wifi location popup
		$( "#side-directions-new" ).bind( "click", function() {
		
			// show #shad-over
				showpopup("#shad-over-directions");
				
			// do not relocate to "#"
				return false;
		
		});
	// end of search a new wifi location popup
	
		// close button in popups
		$( "#shad-over-driving-directions .box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-driving-directions");
	
			// do not relocate to "#"
				return false;
		
		});
	// end of close button in popups
	
	// close button in popups
		$( "#shad-over-register-hotspot .box-top a.close, #shad-over-register-hotspot .box-content .buttons a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-register-hotspot");
	
			// do not relocate to "#"
				return false;
		});
		$( "#shad-over-register-hotspot-step2 .box-top a.close, #shad-over-register-hotspot-step2 .box-content .buttons a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-register-hotspot-step2");
	
			// do not relocate to "#"
				return false;
		});		
		
	// end of close button in popups
	
		// close button in popups
		$( "#shad-over-rate-hotspot .box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-rate-hotspot");
	
			// do not relocate to "#"
				return false;
				
				
		
		});
	// end of close button in popups
	
	
	// close button in popups
		$( "#shad-over-hotspot-rating .box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-hotspot-rating");
	
			// do not relocate to "#"
				return false;
				
				
		
		});
	// end of close button in popups
	
		// close button in popups
		$( "#shad-over-errors .box-top a.close" ).bind( "click", function() {
		
			// hide #shad-over
				hidepopup("#shad-over-errors");
	
			// do not relocate to "#"
				return false;
				
				
		
		});
	// end of close button in popups
	
	
	
});


// flash map	
	function mapIeFix (s)
	{
		if(s=="big")
		document.write( '<object type="application/x-shockwave-flash" data="/jiwire/flash/big_interactive_map_study2.swf" width="560" height="248"><param name="movie" value="/jiwire/flash/big_interactive_map_study2.swf"><param name="allowScriptAccess" value="always"><param name="quality" value="high"><param name="wmode" value="transparent"></object>' );
		else
		document.write( '<object type="application/x-shockwave-flash" data="/jiwire/flash/small_interactive_map_study2.swf" width="265" height="129"><param name="movie" value="/jiwire/flash/small_interactive_map_study2.swf"><param name="allowScriptAccess" value="always"><param name="quality" value="high"><param name="wmode" value="transparent"></object>' );
	}
	
// this function used to get values from the query string
function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) return false;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		value = decodeURIComponent(value);
		args[argname] = value;
	}
	return args;
}
