$.loadFlash = function(agentJsUrl, type) {

    	var agentFileName = 'feature.swf';

	if (type === 'slideShowPro') {
        	var flashvars = {
			paramXMLPath: agentJsUrl + "param.xml"
        	};

        var params = {
            base: agentJsUrl,
            bgcolor: "#0D4475"
        };

        agentFileName = 'slideshowpro.swf';

    } else {
        var flashvars = {};
        var params = { wmode: 'transparent', allowscriptaccess: 'always' };
    }

    var attributes = {}

    var $flashPlaceHolder = $('<div id="flashPlaceHolder"></div>');
    var $feature = $('#feature');

    $flashPlaceHolder.appendTo($feature);

    swfobject.embedSWF(
		agentJsUrl + agentFileName,
		"flashPlaceHolder",
		"100%",
		"100%",
		"9.0.0",
		false,
		flashvars,
		params,
		attributes);

    var timer = 0;



var $obj = $feature.find('object');


$('#feature').css({'visibility':'visible', 'display':'block'});	

var time = setTimeout(function() {

if($obj.length === 0) {
	$('#feature img').css({'visibility':'visible', 'display':'block'});	
	$('#feature p').css({'visibility':'visible', 'display':'block'});	
} else {
	
}

clearTimeout(time);

}, 500);


    var interval = setInterval(function() {
        timer++;
        var $obj = $feature.find('object');
        if ($obj.length !== 0) {
            $feature.find('p').remove();
            $feature.find('img').remove()
            clearInterval(interval);
        } else if (timer > 20) {
           
            clearInterval(interval);
        }
    }, 200);
};

// jQuery Paolo's amazing alert replacement
// Public
jQuery.jAlert = function(message, options) {
    var opts = $.extend({}, $.jAlert.defaults, options);

    var $container = _buildContainer();

    $container.text(message);

    _show($container, opts);
};

jQuery.jAlert.defaults = { duration: 4000 };

// Private
var _buildContainer = function() {
    var $container = $('#jAlert');

    if ($container.length === 0) {
        var $body = $(document.body);
        $container = $('<div id="jAlert"></div>');
        $container.appendTo($body);
    }

    return $container;
};

var _centerInViewport = function($obj) {
    var $viewport = $(window);


    var top = ($viewport.height() / 2) - ($obj.height() / 2);
    var left = ($viewport.width() / 2) - ($obj.width() / 2);

    $obj.css({
        'top': top + 'px',
        'left': left + 'px'
    });

    return $obj;
};

var _explode = function($obj, evt) {
    $obj.fadeOut('fast');
    if (typeof evt !== 'undefined') {
        clearTimeout(evt);
    }
};

var _show = function($obj, opts) {
    _centerInViewport($obj).fadeIn('fast', function() {
        if (opts.duration === 0) {
            var $closeBtn = $('<a class="jAlertCloseBtn">Close</a>');
            $closeBtn.appendTo($obj).fadeIn('slow'); ;
            $closeBtn.click(function() {
                _explode($obj);
            });
        } else {
            setTimeout(function(evt) { _explode($obj, evt); }, opts.duration);
        }
    });
};




jQuery.fn.iFixPng = function() {
    if (!$.support.opacity) {
        return this.each(function() {
            var $this = $(this);

            var cssImage = $this.css('background-image').split('"')[1];

            $this.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + cssImage + '", sizingMethod="scale")');
            $this.css('background-image', 'none');
        });
    }
};

$(document).ready(function() {
    if (typeof ($(".icon_map, .property_details_map, .icon_pdf, .ico_pdf_generic, .icon_map_street_view").colorbox) == 'function') {
        //$(".icon_map, .property_details_map").bind('click', test).colorbox({ iframe: true, width: 800, height: 550, inline: true, href: "#google_map" }, function() { $("#google_map").css({ 'visibility': 'visible', 'width': '100%', 'height': '100%', 'margin-top': '0' }); });
        $(".icon_map, .property_details_map").bind('click', test).colorbox({ iframe: true, width: 800, height: 550 });
        $(".icon_pdf, .ico_pdf_generic").colorbox({ width: $(window).width(), height: $(window).height(), iframe: true });
        $(".icon_map_street_view").colorbox({ width: 845, height: 550, iframe: true, scrollbars: false });	 
	$(".icon_vr").colorbox({ width: 650, height: 650, iframe: true });
    }
});

var test = function() {
    $().bind('cbox_closed', function() {
        $('#google_map').css('visibility', 'hidden');
        $().unbind('cbox_closed');
    });
};

// JavaScript Document

$(document).ready(function() {

    $("a img").hover(function() {
        $(this).addClass("iehover");
    }, function() {
        $(this).removeClass("iehover");
    });

    $(":input").focus(function() {
        $(this).addClass("iefocus");
    });

    $(":input").blur(function() {
        $(this).removeClass("iefocus");
    });

    $.fn.clean = function() {
        return this.focus(function() {
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function() {
            if (!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    };

    $('.slide').hide();
    $('.trigger').click(function() {
        var $nextDiv = $(this).next();
        var $visibleSiblings = $nextDiv.siblings('p.slide:visible');
        if ($visibleSiblings.length) {
            $visibleSiblings.slideUp('fast', function() {
                $nextDiv.slideToggle('fast');
            });
        } else {
            $nextDiv.slideToggle('fast');
        }
    });

    $('.trigger').toggle(function() {
        $('h4.trigger').addClass('close');
    }, function() {
        $('h4.trigger').removeClass('close'); ;
    });


    if ($("#propertylist ul").length) {
        $("#propertylist").css("display", "");
    }
    else {
        $("#propertylist").css("display", "none");
    }





    $('.pDetailsIcons, .logoFooter').iFixPng();

    window.alert = $.jAlert;

    $('#feature').fadeIn('fast', function() { $('#flashPlaceHolder').fadeIn('fast'); });
});