jQuery.noConflict();

var portraitChanger  = {
	timeout: {},
	responseText: "",
	init: function() {
		jQuery('ol.portrait-set').each(function() {
			var id = this.id.replace(/portrait-set-/,"");
//			jQuery("h2#portrait-title").after('<a id="portrait-changer-link" class="ir btn-see-our-other-properties" href="javascript:portraitChanger.changePortraitViaLink('+id+')"><span>See our other properties</span></a>');
			portraitChanger.timeout = setTimeout("portraitChanger.changePortrait("+id+")",7000);
		});
	},
	/*changePortraitViaLink: function(id){
		clearTimeout(portraitChanger.timeout);
		portraitChanger.changePortrait(id);
	},*/
	changePortrait: function(id){
//		jQuery('a#portrait-changer-link').attr('href','javascript:return false');
		jQuery.get('/home/requestPortrait/'+id, {}, function(responseText, textStatus){ 
			if(textStatus == "success") {
				portraitChanger.responseText = responseText;
				jQuery("#portraits-container").fadeOut(function() {
					jQuery(this).html(portraitChanger.responseText);
					if(jQuery('h2').hasClass('purple')){
						jQuery('#portraits-container').addClass('purple');	
					}else{
						jQuery('#portraits-container').removeClass('purple');							
					}
					jQuery('#portraits-container ol').css('display','none');
					jQuery('#portraits-container').fadeIn(function() {
							jQuery('#portraits-container ol').fadeIn();
					});
					// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
					jQuery(function($) {
						$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
							return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
						});
					});
					
					portraitChanger.init();
				});
			}
		}); 
	}
};

jQuery(document).ready(function(){
	//Google maps
    if (GBrowserIsCompatible() && document.getElementById('map')) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(51.51817,-0.139544), 16);
		var point = new GLatLng(51.51817,-0.137544);
		map.addOverlay(new GMarker(point));
		
	    var newP = document.createElement("div");
		newP.innerHTML = "<strong>Circle Apartments</strong><br/>Michele House, 45 - 46 Berners Street, London, W1T 3NE";
		
		map.openInfoWindowHtml(point, newP);
    }
    
	//Grab submit input elements and replace with <a> and onclick to submit form
	jQuery('.submit input').each(function() {
		var val = jQuery(this).val();
		jQuery(this).replaceWith('<a rel="'+val.toLowerCase()+'" class="submit-btn ir btn-'+val.toLowerCase()+'" href="#"><span>'+val+'</span></a>');
	});
	jQuery('a.submit-btn').click(function () {
		jQuery('#'+this.rel+'-form').submit();
		return false;
	});
	if(jQuery('ol.portrait-set')) {
		portraitChanger.init();
	}
});
