var $m = jQuery;

$m(document).ready(function(){
	
	/*
	$('ID/Class').innerfade({ 
		animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
		speed: Fadingspeed in milliseconds or keywords - slow, normal or fast (Default: 'normal'), 
		timeout: Time between the fades in milliseconds (Default: '2000'), 
		type: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
		containerheight: Height of the containing element in any css-height-value (Default: 'auto')  
		runningclass: CSS-Class which the container get’s applied (Default: 'innerfade') }); 
	*/
	$m('#homeSlideshow').innerfade({
		animationtype: 'fade',
		speed: 1500, 
		timeout: 4000, 
		type: 'sequence',
		containerheight: '333px'
	});
	
	$m(".rssLinkListItemDesc img").parent().parent().parent().addClass("hasImage");
	
	/* This way preserves the outer link around the images
	$m(".hasImage div.rssLinkListItemDesc").each(function () {
		var rssLinkImage = $m("<div>").append($m(this).children("a").clone()).remove().html();
		$m(this).html(rssLinkImage);											 
	});
	*/

	/* IE possibly hates this?
	$m(".hasImage div.rssLinkListItemDesc").each(function () {
		var rssLinkImage = $m("<span class='image'>").append($m(this).children("a").children("img").clone()).html();
		$m(this).html(rssLinkImage);											 
	});
	*/

	$m("div.rssLinkListItem:not('.hasImage')").append("<div class='noImage'>&nbsp;</div>");
	
	$m("div.rssLinkListItem").each(function () {
		var thisTitle = $m("<div>").append($m(this).children("span.rssLinkListItemTitle").clone()).remove().html();
		var thisDescr =  $m("<div>").append($m(this).find("img:first").clone()).remove().html();
		var thisNoImage = $m("<div>").append($m(this).children("div.noImage").clone()).remove().html();
		var thisContents = $m("<div>").append(thisDescr).append(thisNoImage).append(thisTitle);
		$m(this).html(thisContents);											 
	});
	
	$m(".rssLinkListItem img").wrap("<span class='image'></span>");
	
	$m(".rssLinkListItemTitle a").each(function(){
		var originalLink = $m(this).attr("href");
		updatedLink = originalLink.replace(/idx.diversesolutions.com\/search\/[^s]+\/source\/rss/gi,"www.texasmls.com/buy/dallas-fortworth-mls-home-search/");
		$m(this).attr("href", updatedLink);
	});
	
	var propertyID = window.location.href.slice(window.location.href.indexOf("#") + 1);
	if ( $m(propertyID).length ) {
		var URLwithPropertyID = "http://idx.diversesolutions.com/search/2660/15#" + propertyID;
		$m("#_dsSearchAgent_Idx_Frame_0").attr('src', URLwithPropertyID);
	};

}); 