$(document).ready(function() {

    $('#dHeader ul, #dFooter ul').RemoveLastBorder();



    $('.iwkContactForm .btnSend').StyleButton({ cssClass: 'styledButton' });
    $('.iwkRecruitment a.btnSubmit').StyleButton({ cssClass: 'styledButton' });
    $('.iwkAdvancedSearch a.btnSearch').StyleButton({ cssClass: 'styledButton' });
    $('.iwkSimpleSearch a.btnSearch').StyleButton({ cssClass: 'styledButton' });
    $('.iwkPropertyDetail .requestSendAction a').StyleButton({ cssClass: 'styledButton' });
    $('.newsletter a').StyleButton({ cssClass: 'styledButton' });

    if ($('.iwkPropertyDetail').length > 0) {

        //Duplicate Property Owner's Info to side container
        $('#ownerInfoContainer').append($('#tabOwner'));

        //Duplicate Property Owner's Info to side container
        if ($('#tabVideos').length > 0)
            $('#videoContainer').append($('#tabVideos'));
        else
            $('#videoContainer').parent().hide();

    }

    setInterval("BannerSlideshow()", 5000);

});


/*	@ Remove last navigation's borders plugin
    ======================================================================================== */

function BannerSlideshow() {

    var $active = $("#dBanner img.active");

    if ($active.length == 0)
        $active = $("#dBanner img:last");

    var $next = $active.next().length ? $active.next() : $("#dBanner img:first");

    $active.addClass("last-active");

    $next.css({ opacity: 0.0 })
    	.addClass("active")
    	.animate({ opacity: 1.0 }, 1000, function() {
    	    $active.removeClass("active last-active");
    	});

}



/*	@ Remove last navigation's borders plugin
	======================================================================================== */
$.fn.RemoveLastBorder = function(options){
	return this.each(function(){
		$(this).children('li').filter(':last').css('border','none');
	});
};


/*	@ Style Buttons
	======================================================================================== */
$.fn.StyleButton = function(options) {
	var defaults = { cssClass:'' }
	var options = $.extend(defaults, options);
	return this.each(function(){
		var buttonText = $(this).text();
		$(this).addClass(options.cssClass).html('<span>' + buttonText + '</span>');
	});	
};
