﻿$(document).ready(function() {
    var selectContainerHtml = "<div class='jom-select-container'></div>";
    var selectSiblings = "<div class='jom-select-text'></div><div class='jom-select-button'></div>";
    var selectOnChange = "customSelectBoxChanged(this);";

	if (typeof document.body.style.maxHeight != "undefined")    
	{
	    var selectBoxes = $("select");
	    if(selectBoxes != null && selectBoxes != undefined)
	    {
		    for(var i=0;i < selectBoxes.length;i++)
			{
				if(selectBoxes.eq(i).parents(".ms-ToolPaneOuter").length == 0)
				{
				    selectBoxes.eq(i).wrap(selectContainerHtml);
				    selectBoxes.eq(i).before(selectSiblings);
		
				    selectBoxes.eq(i).addClass("jom-select");
		
				    selectBoxes.eq(i).bind("change",
							        function() {
										            customSelectBoxChanged(this);
										        }
								    );
			        customSelectBoxChanged(selectBoxes[i]);
				}
			}
		}
	}
    if ($("#ctl00_PlaceHolderSearchArea_ctl01_S6AE27B38_InputKeywords").val() == '') { $("#ctl00_PlaceHolderSearchArea_ctl01_S6AE27B38_InputKeywords").val("search our site"); };
        $("#ctl00_PlaceHolderSearchArea_ctl01_S6AE27B38_InputKeywords").blur(function() { if (this.value == '') this.value = 'search our site'; });
        $("#ctl00_PlaceHolderSearchArea_ctl01_S6AE27B38_InputKeywords").focus(function() { if (this.value == 'search our site') this.value = ''; });
});

function customSelectBoxChanged(selectBox) {
    var jqSelectBox = jQuery(selectBox);
    var jqContainer = jqSelectBox.parent();
    var jqButtonBox = jqSelectBox.siblings(".jom-select-button");
    var jqTextBox = jqSelectBox.siblings(".jom-select-text");

    jqTextBox.html(selectBox.options[selectBox.selectedIndex].innerHTML);

    jqButtonBox.css("left", jqSelectBox.width() - jqButtonBox.width());
    jqTextBox.css("width", jqSelectBox.width() - jqButtonBox.width() + 15);
    jqSelectBox.css("margin-left", (0 - jqSelectBox.width()));
}
