$(window).bind('load',function() {
	$('#page-loading').fadeOut('fast').remove();
	$('.locations-box,.location-details-box').css({top:'auto'});
	$('.main_content_home').animate({opacity:1},'fast');
	var cities = new Array;
	if($('.home_mfame_city').length) {
		$('.home_mfame_city').each(function() {
		
			var city_src,city_title,city_body = '';
			
			var city_src = $('img', this).attr('src');
			var city_title = $('h2',this).attr('innerHTML');
			var city_body = $('p',this).attr('innerHTML');
			var city_href = $('a',this).attr('href');
			cities[cities.length] = {
				title: city_title,
				src: city_src,
				href: city_href,
				body: city_body
			};
		});
	}
	if (cities.length > 0) {
	
		$('#home_frame_images img').remove();
		
		$(cities).each(function(i,item) {
			var city = $(this).get(0);
			$('#home_frame_images').append('<img src="'+city.src+'" alt="'+city.title+'" rel="'+parseInt(i)+'"/>');
		});
		$('#home_frame_images').cycle({
			timeout:4500,
			speed:1000,
			containerResize:0,
			before: function(currItem, nextItem, options, forwardFlag) {
				var id = $(nextItem).attr('rel');
				$('.locations li a').removeClass('active');
				$('.locations li a').each(function(i,item) {
					if (cities[id].title == $(item).html()) {
						$(item).addClass('active');
					}
				});
				$('.location-details-box .content p').html(cities[id].body);
				$('.location-details-box .content a').attr('href',cities[id].href);				
				$('.location-details-box .title').html(cities[id].title);
				Cufon.refresh();
			}
		});
	}
	/*
	$('.locations li a').click(function() {
		this_city = $(this).attr('innerHTML');
		$(cities).each(function(i,item) {
			if (item.title == this_city) {
				$('#home_frame_images').cycle(i);
				$('#home_frame_images').cycle('pause');
				return false;
			}
		});
		return false;
	});	
	*/
	
});

$(document).ready(function() {
  $('.whats-new-box').hover(function() {
    $(this).addClass('hover');
  },function() {
    $(this).removeClass('hover');
  });
  
  $('.whats-new-box').click(function(e) {
    if (e.target.tagName == 'A') { } else {
      if ($('a',this).length == 1) {
        if ($('a',this).attr('target') == '_blank') {
          window.open($('a',this).attr('href'));
        } else {
          window.location = $('a',this).attr('href');
        }
      } else {
        if ($('.read-more',this).attr('target') == '_blank') {
          window.open($('.read-more',this).attr('href'));
        } else {
          window.location = $('.read-more',this).attr('href');
        }
      }
    }
  });
  
	$('.site-container table table').animate({opacity:1});

	// Cufon
	Cufon.replace('.locations-box .title', { fontFamily: 'FuturaBook' });
	Cufon.replace('.locations-box span', { fontFamily: 'FuturaBook' });
	Cufon.replace('.featured-title,.furnished-title', { fontFamily: 'FuturaBook' });
	Cufon.replace('.location-details-box .title', { fontFamily: 'FuturaMedium' });
	Cufon.replace('.vertica-copy h1', { fontFamily: 'FuturaBook' });
	Cufon.replace('.whats-new .title', {fontFamily: 'FuturaBook' });
	
});

// ROLL OVER

var imageOn = new Array();
var imageOff = new Array();
var imageDirectory;

function initRollovers()
{
	if (document.images)
	{
		for (var i = 0; i < imageOnFiles.length; i++)
		{
			currentName = imageTagNames[i];
			imageOff[currentName] = new Image();
			imageOn[currentName] = new Image();
			imageOff[currentName].src = imageDirectory + imageOffFiles[i];
			imageOn[currentName].src = imageDirectory + imageOnFiles[i];
		}
	}
}

function rollon(img)
{
	if (document.images && imageOn[img])
	{
		document.images[img].src = imageOn[img].src;
	}
}

function rolloff(img)
{
	if (document.images && imageOff[img])
	{
		document.images[img].src = imageOff[img].src;
	}
}

