/*================================
 POWER ELECTRONICS
 jquery-settings.js
 
 Last Updated By: Ryan Perry
 Last Updated: 03/31/2010
================================*/
$(document).ready(function(){	



$(".search").bind("keypress", function(e) {
	

	if(e.keyCode == 13)
	{
	    e.returnValue = false;
	    e.cancel = true;
	    $(".search .btn-go").click();
	    return false;
	}
});



/*================================================
 Main Navigation Drop-Down Menu
================================================*/
$(".nav-container ul.nav").superfish({
	hoverClass: 'hover',
	autoArrows: false,
	delay: 200, 
	dropShadows: true,
	animation:	{opacity:'show',height:'show'}
});


/*================================================
  IE6 Hover Fix
================================================*/
$("h3.accordion-header").hover(function() {
	$(this).addClass("accordion-header-hover");}, 
	function() {$(this).removeClass("accordion-header-hover");
});

$("h4.accordion-sub-header").hover(function() {
	$(this).addClass("accordion-sub-header-hover");}, 
	function() {$(this).removeClass("accordion-sub-header-hover");
});

$(".accordion-content .accordion-sub-row-data").hover(function() {
	$(this).addClass("accordion-sub-row-hover");}, 
	function() {$(this).removeClass("accordion-sub-row-hover");
});

$(".accordion-content .accordion-row-data").hover(function() {
	$(this).addClass("accordion-row-hover");}, 
	function() {$(this).removeClass("accordion-row-hover");
});


/*================================================
  jQuery Tabs
================================================*/
/*---- Tab Display ----*/
if(jQuery().tabs) {
	//Plugin Installed
	
	/*---- Home Page Industry Tab Content ----*/
	$(".content-container .industry-nav .tab-container").tabs({selected: 0});
	$(".content-container .industry-nav .tab-content .tab-item").css({"display" : "block"});
	
	
} else {
	//Plugin Not Installed
}


/*================================================
 Literature Library Accordion
================================================*/
/*---- Accordion Top Level ----*/
$(".accordion-container").accordion({
	header: "h3.accordion-header", 
	active: false,
	alwaysOpen: false,
	autoHeight: false,
	clearStyle: true
});	

if (jQuery.browser.msie) {
	 $('.accordion-container div').css('zoom', '1'); 
}; 

/*---- Accordion Sub Level ----*/
$(".accordion-sub-container").accordion({
	header: "h4.accordion-sub-header", 
	active: false,
	alwaysOpen: false,
	autoHeight: false,
	clearStyle: true
});	

if (jQuery.browser.msie) {
	 $('.accordion-sub-container div').css('zoom', '1'); 
}; 


/*---- Add Alternating Background For Top Level ----*/
$(".accordion-container h2 + .accordion-item").addClass("first-item");
$(".first-item").siblings(".accordion-item:nth-child(odd)").children(".accordion-header").addClass("alt-bg");





/*================================================
 Home Page Image Rotator
================================================*/
$(".home-container .feature").cycle({
	fx: 'fade'	,
	timeout: 4000	
});


/*================================================
 File Input Replacement (File Upload)
================================================*/
/*
$(".form-layout input[type=file]").filestyle({ 
	image: "images/btn-browse-for-file.png",
	imageheight : 23,
	imagewidth : 123,
	width : 250
});		
*/


/*================================================
 Form Builder Radio/Checkbox Other Textfield Requirement
================================================*/
 /*---- Primary Configuration Option Other ----*/  
$("#txt_Primary_Other").attr("disabled", true); 
$("#txt_Primary_Other").css({"background" : "#efefef"});	

$("#chk_Primary_Configuration input").each(function(index){								  
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Primary_Other").attr("required", "True");
		$("#txt_Primary_Other").removeAttr("disabled");
		$("#txt_Primary_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Primary_Other").attr("required", "False");
		$("#txt_Primary_Other").attr("disabled", true); 
		$("#txt_Primary_Other").css({"background" : "#efefef"});
		$("#txt_Primary_Other").val('');
	}});
});  

 /*---- Secondary Configuration Option Other ----*/  
$("#txt_Secondary_Other").attr("disabled", true); 
$("#txt_Secondary_Other").css({"background" : "#efefef"});	

$("#chk_Secondary_Configuration input").each(function(index){								  
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Secondary_Other").attr("required", "True");
		$("#txt_Secondary_Other").removeAttr("disabled");
		$("#txt_Secondary_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Secondary_Other").attr("required", "False");
		$("#txt_Secondary_Other").attr("disabled", true); 
		$("#txt_Secondary_Other").css({"background" : "#efefef"});
		$("#txt_Secondary_Other").val('');
	}});
});  


/*---- Control Radio Option Other ----*/  
$("#txt_Control_Other").attr("disabled", true); 
$("#txt_Control_Other").css({"background" : "#efefef"});	

$("#chk_Control input").each(function(index){								  
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Control_Other").attr("required", "True");
		$("#txt_Control_Other").removeAttr("disabled");
		$("#txt_Control_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Control_Other").attr("required", "False");
		$("#txt_Control_Other").attr("disabled", true); 
		$("#txt_Control_Other").css({"background" : "#efefef"});
		$("#txt_Control_Other").val('');
	}});
});  


 /*---- Mounting Radio Option Other ----*/  
$("#txt_Mounting_Other").attr("disabled", true); 
$("#txt_Mounting_Other").css({"background" : "#efefef"});	

$("#chk_Mounting input").each(function(index){
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Mounting_Other").attr("required", "True");
		$("#txt_Mounting_Other").removeAttr("disabled");
		$("#txt_Mounting_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Mounting_Other").attr("required", "False");
		$("#txt_Mounting_Other").attr("disabled", true); 
		$("#txt_Mounting_Other").css({"background" : "#efefef"});
		$("#txt_Mounting_Other").val('');
	}});
});  


 /*---- Temperature Radio Option Other ----*/  
$("#txt_Temperature_Other").attr("disabled", true); 
$("#txt_Temperature_Other").css({"background" : "#efefef"});		

$("#chk_Temperature input").each(function(index){
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Temperature_Other").attr("required", "True");
		$("#txt_Temperature_Other").removeAttr("disabled");
		$("#txt_Temperature_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Temperature_Other").attr("required", "False");
		$("#txt_Temperature_Other").attr("disabled", true); 
		$("#txt_Temperature_Other").css({"background" : "#efefef"});	
		$("#txt_Temperature_Other").val('');
	}});
});  


 /*---- Learn About Us Checkbox Option Other ----*/  
$("#txt_LearnAboutUs_Other").attr("disabled", true); 
$("#txt_LearnAboutUs_Other").css({"background" : "#efefef"});

$("#chk_LearnAboutUs input").each(function(index){
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_LearnAboutUs_Other").attr("required", "True");
		$("#txt_LearnAboutUs_Other").removeAttr("disabled");
		$("#txt_LearnAboutUs_Other").css({"background" : "#ffffff"});
		
	} else {
        $("#txt_LearnAboutUs_Other").attr("required", "False");
		$("#txt_LearnAboutUs_Other").attr("disabled", true); 
		$("#txt_LearnAboutUs_Other").css({"background" : "#efefef"});
		$("#txt_LearnAboutUs_Other").val('');
	}});
});  


 /*---- Profile Checkbox Option Other ----*/ 
$("#txt_Profile_Other").attr("disabled", true); 
$("#txt_Profile_Other").css({"background" : "#efefef"}); 

$("#chk_Profile input").each(function(index){
  $(this).bind("click", function(e){ 
    if($(this).val().indexOf("Other") != -1) {
        $("#txt_Profile_Other").attr("required", "True");
		$("#txt_Profile_Other").removeAttr("disabled");
		$("#txt_Profile_Other").css({"background" : "#ffffff"});		
	} else {
        $("#txt_Profile_Other").attr("required", "False");
		$("#txt_Profile_Other").attr("disabled", true); 
		$("#txt_Profile_Other").css({"background" : "#efefef"});	
		$("#txt_Profile_Other").val('');
	}});
});  


 /*---- AC Power Centers Checkbox Option Other ----*/  
$("#txt_ACPowerCenters_Other").attr("disabled", true); 
$("#txt_ACPowerCenters_Other").css({"background" : "#efefef"}); 

$("#chk_ACPowerCenters span label:contains('Other')").prev("input").bind("click", function() {	
	if($(this).attr("checked") == true) {
		$(this).attr("checked", true);
		$("#txt_ACPowerCenters_Other").attr("required", "True");
		$("#txt_ACPowerCenters_Other").removeAttr("disabled");
		$("#txt_ACPowerCenters_Other").css({"background" : "#ffffff"});					
	} else {
		$(this).attr("checked", false);
		$("#txt_ACPowerCenters_Other").attr("required", "False");
		$("#txt_ACPowerCenters_Other").attr("disabled", true); 
		$("#txt_ACPowerCenters_Other").css({"background" : "#efefef"});
		$("#txt_ACPowerCenters_Other").val('');		
	}
});


 /*---- DC Power Centers Checkbox Option Other ----*/ 
$("#txt_DCPowerCenters_Other").attr("disabled", true); 
$("#txt_DCPowerCenters_Other").css({"background" : "#efefef"});	


$("#chk_DCPowerCenters span label:contains('Other')").prev("input").bind("click", function() {	
	if($(this).attr("checked") == true) {
		$(this).attr("checked", true);
		$("#txt_DCPowerCenters_Other").attr("required", "True");
		$("#txt_DCPowerCenters_Other").removeAttr("disabled");
		$("#txt_DCPowerCenters_Other").css({"background" : "#ffffff"});					
	} else {
		$(this).attr("checked", false);
		$("#txt_DCPowerCenters_Other").attr("required", "False");
		$("#txt_DCPowerCenters_Other").attr("disabled", true); 
		$("#txt_DCPowerCenters_Other").css({"background" : "#efefef"});
		$("#txt_DCPowerCenters_Other").val('');		
	}
});


 /*---- AC/DC Drive Systems Checkbox Option Other ----*/ 
$("#txt_AC_DC_DriveSystems_Other").attr("disabled", true); 
$("#txt_AC_DC_DriveSystems_Other").css({"background" : "#efefef"});	

$("#chk_AC_DC_DriveSystems span label:contains('Other')").prev("input").bind("click", function() {	
	if($(this).attr("checked") == true) {
		$(this).attr("checked", true);
		$("#txt_AC_DC_DriveSystems_Other").attr("required", "True");
		$("#txt_AC_DC_DriveSystems_Other").removeAttr("disabled");
		$("#txt_AC_DC_DriveSystems_Other").css({"background" : "#ffffff"});					
	} else {
		$(this).attr("checked", false);
		$("#txt_AC_DC_DriveSystems_Other").attr("required", "False");
		$("#txt_AC_DC_DriveSystems_Other").attr("disabled", true); 
		$("#txt_AC_DC_DriveSystems_Other").css({"background" : "#efefef"});
		$("#txt_AC_DC_DriveSystems_Other").val('');		
	}
});


 /*---- Literature Library State Other ----*/  
$(".other .form-textbox").attr("disabled", true); 
$(".other .form-textbox").css({"background" : "#efefef"});	

//$(".registration-form .state .form-selectbox").change(function () {
//																
//	if ($(".registration-form .state .form-selectbox option:selected").attr('Value') == "Other") {		
//		//alert("Other Selected");
//		$(".other .form-textbox").attr("required", "true");
//		$(".other .form-textbox").attr("disabled", false); 
//		$(".other .form-textbox").css({"background" : "#ffffff"});
//	} else {		
//		//alert("A U.S. State has been selected");
//		$(".other .form-textbox").attr("required", "False");
//		$(".other .form-textbox").attr("disabled", true); 
//		$(".other .form-textbox").css({"background" : "#efefef"});
//		$(".other .form-textbox").val('');
//	}
//}); 

//$(".registration-form .btn-submit-registration").attr("disabled", false);



/*================================================
 Add Asterisk  for Required Fields 
================================================*/
/*---- Input Textboxes/Textarea ----*/
$(".form-body .form-row .form-textbox[required $= True]").prev(".form-label").append("<span class='form-required'> *</span>");

/*---- Selectboxes ----*/
$(".form-body .form-row .form-selectbox[required $= True]").prev(".form-label").append("<span class='form-required'> *</span>");

/*---- Checkboxes ----*/
$(".form-body .form-row .form-checkbox[required $= True]").prev(".form-label").append("<span class='form-required'> *</span>");



/*---- Default Text Value (Hint) ----*/  
$('input[defaulttext!=""]').each(function(i) {

    var $input = $(this),

    // capture the rest of the variable to allow for reuse
	                    title = $input.attr('defaulttext'),
	                    $form = $(this.form),
	                    $win = $(window);

    function remove() {
        if ($input.val() === title && $input.hasClass('blur')) {
            $input.val('').removeClass('blur');
        }
    }

    // only apply logic if the element has the attribute
    if (title) {
        // on blur, set value to title attr if text is blank
        $input.blur(function() {
            if (this.value === '') {
                $input.val(title).addClass('blur');
            }
        }).focus(remove).blur(); // now change all inputs to title

        // clear the pre-defined text when form is submitted
        $form.submit(remove);
        $win.unload(remove); // handles Firefox's autocomplete
    }


});

});
