$(document).ready(function() {

	$('#HomeHeroImage').removeClass('hidden');
	$('#HeroImageNoScript').addClass('hidden');
	$('.HomeHeroButtons').removeClass('hidden');
	
    var heroImages = $('#HomeHeroImage').cycle({
        fx: 'fade',
        speed: 300,
        timeout: 3000,
        next: '.HomeHeroNavNext',
        prev: '.HomeHeroNavPrev',
        pause: 1
    });

    var search_defaulttext = "";

    $('input.searchbox')
	        .data('dirty', false)
	        .val(search_defaulttext)
	        .bind('search', function(e) {
	            var $this = $(this);
	            if ($this.data('dirty')) {
	                var rooturl = $this.prev('input[type=hidden]').val();
	                var url = rooturl + "search.aspx?q=" + escape($.trim($this.val()));
	                window.location.href = url;
	            }
	        })
	        .keypress(function(e) {
	            if (e.which == 13) {
	                e.stopPropagation();
	                e.preventDefault();
	                $(this).trigger('search');
	            }
	        })
			.focus(function(e) {
			    e.stopPropagation();
			    e.preventDefault();
			    var $this = $(this);
			    if (!$this.data('dirty')) {
			        $this
			            .data('dirty', true)
			            .val('');
			    }
			});

    $('input.searchbutton').click(
			function(e) {
			    e.stopPropagation();
			    e.preventDefault();
			    $(this).closest('table').find('.searchbox').trigger('search');
			}
		);

    // cancel the edit page unload function when debugging
    window.onbeforeunload = null;

    // NOTE: Need to replace the function defined in the Telerik RadEditor version 7_2_1
    // of the MOSSEditorTools.js since it bugs out in IE for the reusable content
    if (typeof RadEditorCommandList != 'undefined') {
        RadEditorCommandList["MOSSTemplateManager"] = function(commandName, editor, oTool) {
            if (!RadE_HasRules) {
                RTE2_InstantiateStaticSafeHtmlRules();
                RadE_HasRules = true;
            }
            var docEditor = editor.Document;
            var params = editor.GetDialogParameters("MOSSParams");
            var configObj = new AssetPickerConfig("");
            configObj.ClientID = editor.Id;
            configObj.DefaultAssetLocation = "";
            configObj.CurrentWebBaseUrl = params["CurrentWebBaseUrl"];
            configObj.AllowExternalUrls = params["AllowExternalUrls"];
            var bInserting = false;
            var elemToReplace = null;
            var fragmentId = null;
            var elemViewToEdit = FormJSRTE_GetNearestContainingParentElementOfTypes(editor.ContentWindow.frameElement.id, RadE_GetCurrentElement(docEditor), new Array("SPAN"));
            if ((elemViewToEdit != null) && (elemViewToEdit.id == g_strRTE2ReusableFragmentCommonToken)) {
                fragmentId = elemViewToEdit.getAttribute("fragmentid");
            }
            var dialogInput = new Object();
            dialogInput.fragmentId = fragmentId;
            var callback = function(dialogOutput) {
                if ((dialogOutput != null) && (dialogOutput.fragmentView != null)) {
                    //alert("running replacement function");
                    // NOTE: Removed the selection code as in IE it was using the main document's
                    // window to paste the HTML instead of th iframe's window                
                    editor.PasteHtml(dialogOutput.fragmentView);
                    RTE2_AlterReusableFragmentHighlights(docEditor.body, "ms-reusableTextView");
                }
            };
            var dialogUrl = params["CurrentWebBaseUrl"] + "/_layouts/ReusableTextPicker.aspx";
            commonShowModalDialog(dialogUrl, "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;", callback, dialogInput);
        }
    }
});