// BlueSoap (c) 2011
// Settings
var enable_cufon = true, fontname = "verdana", enable_gmaps = true;

window.addEvent('load',function() {
//	document.id(document.body).tween('opacity', '0', '1');
});

window.addEvent('domready',function() {
		
	// To avoid @mail snopping, let do a quick change from [at] > @
//	document.id(document.body).set('html', document.id(document.body).get('html').replace(/\[at\]/gi, "@"));
//	!window.Cufon || Cufon.refresh();
	
	$$(".email").each(function(e) {
		if ( e.get('href') != null ) e.set("href", e.get('href').replace(/\[at\]/gi, "@"));
		if ( e.get('html') != null ) e.set("html", e.get('html').replace(/\[at\]/gi, "@"));
	});

	new Fx.Accordion(document.id('faq_section'), '#faq_section h3', '#faq_section div', {
		onComplete: function(){
			
		}
	});
	
	$(document.body).addEvent("mousemove", function() {
		Cufon.refresh();
	});
  
});

/* Tweets */
var tweetsList = document.id("twitter") || null;
if(tweetsList) {
	
	tweetsList = tweetsList.getElement("ul");
	
	(function($){
		// Function to format tweets
		function handleTweets(tweets, i) {
			// Start HTML var
			var html = "";
			// For every tweet....
			tweets.each(function(tweet, i) {
				// Append string...
				dd = '<span class="post-info"><abbr class="published">' +  Date.parse(tweet.created_at).timeDiffInWords() + '</abbr> <b>&middot;</b> <a href="http://twitter.com/#!/HomeMove/status/' + tweet.id_str + '" target="_blank">tweet</a></span>';
				cs = ( i == 2 ) ? 'class="last-child"' : '';
				html += "<li "+cs+">" + tweet.text.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1#<a href="http://search.twitter.com/search?q=%23$2">$2</a>') + dd + "</li>";
			});
			// Add tweets to pane
			tweetsList.set("html",html);
			// Fade in
			document.id("twitter").fade(1);
		}
		// Create an array for tweets
		var tweets = [];
		// If LocalStorage is available
		var storage;

		// If there are no tweets, get them
		if(!tweets.length) {
			//JSONP to the rescue
			new Request.JSONP({
				url: ('https:' == document.location.protocol ? 'https://' : 'http://') + 'twitter.com/statuses/user_timeline/homemove.json?count=3',
				timeout: 3000,
				callbackKey: "callback",
				onComplete:function(data,i) {
					// If tweets
					if(data.length) {
						// Save 'em!
//						if(storage){
//							storage.set("tweets",data);
							handleTweets(data,i);
//						}
					}
				}
			}).send();
		}
		else {
			handleTweets(tweets);
		}
	}(document.id));
}

if ( ( document.id("latitude") && document.id("longitude") ) && enable_gmaps ) {
	
	// Google Maps || MMap

//	google.maps || document.write('<script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false">\x3C/script>');
//	document.write('<script src="/scripts/mmap.main.js">\x3C/script>');
//	document.write('<script src="/scripts/mmap.marker.js">\x3C/script>');

	(function($){
	
		window.addEvent('domready', function(){
											 
			var  LatLng = {
				lat : document.id("latitude") ? document.id("latitude").get("text") : 0,
				lng : document.id("longitude") ? document.id("longitude").get("text") : 0
			}
		
			var map = new google.maps.Map($('gmap'), {
				zoom: 11,
				center: new google.maps.LatLng(LatLng.lat, LatLng.lng),
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				scaleControl: true,
			});
		
			var marker1 = new MMap.Marker.Image({
				map: map,
				title: 'HomeMove',
				image: '/images/icons/google-map-icon.png',
				position: new google.maps.LatLng(LatLng.lat, LatLng.lng)
			});
		
			(function() {map.setZoom(14);}).delay(500);
			
		});
	
	}(document.id));
	
}

	// Cufon Font Replacement

if ( enable_cufon ) {
		
	document.write('<script src="/Scripts/fonts/cufon.js">\x3C/script>');
	document.write('<script src="/Scripts/fonts/' + fontname + '.woff.font.js">\x3C/script>');

	(function() { 
		Cufon.refresh(); 
			  
		// Lets do some font replacement!
		Cufon.replace('#nav li a', { hover:true, textShadow: '0 1px 1px rgba(0, 0, 0, 0.3)',  hoverables: { a: true, span: true, strong: true }} ); 
		Cufon.now();		  
	}).delay(500);
	
}

function popupform(c) {
	
	LeftPosition = (screen.width) ? (screen.width-550)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-450)/2 : 0;
	if (!window.focus)return true;
		window.open(c, '', 'height=450,width=550,scrollbars=no,location=no,status=no,toolbars=no,top='+TopPosition+',left='+LeftPosition);
	
	return true;
}
