/**
 * @author patric.dosch
 */
//associative array of form-id and linked validators
//receives constructed validators on load
var validators = new Array();
//associative array of form-id and linked validatorContructors
var validatorConstructors = new Array();

$(document).ready(function(){
    FeatureList.initFeatureList();
    WhitePaperForm.initWhitePaperForm();
    initFormDefaults();
});

function initFormDefaults(){
    $('input.text, textarea, select', $('form div.compact')).inputLabel(false, {
        color: "#666"
    });
}

var WhitePaperForm = {
	selector: 'div.social-media-white-paper-order',
	init: 'div.social-media-white-paper-order .content-init',
	alterna: 'div.social-media-white-paper-order .content-alterna',
	inputf: 'input#order-email-0, input#order-email-1, input#order-email-2',
		

	initWhitePaperForm: function () {
		
		$(WhitePaperForm.inputf).click(function(){
			$(this).parents(WhitePaperForm.selector).unbind("mouseover").unbind("mouseout");
		});
		

		$(WhitePaperForm.selector).hover(

			    /* ==== OVER ==== */
				function () {
					$(this).find("div.content-init").hide();
					$(this).find("div.content-alterna").show();
					$(this).addClass("darked");
				},
				
				/* ==== OUT ==== */ 
				function () {
					$(this).find("div.content-init").show();
					$(this).find("div.content-alterna").hide();
					$(this).removeClass("darked");
				}
			)
	}
}

function submitAjaxForm(that){
    var valid = validateOnSubmit(that.id);
    if (valid) {
        //clear empty and not mandatory fields
        $('.inputlabel', that).each(function(){
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        });
       
	   var ajaxUrl = "/_resources/ajax/"+that.id.replace("-form", "")+".php";
	   
	   //@FIXME
	   ajaxUrl = ajaxUrl.replace("-0", "");
	   ajaxUrl = ajaxUrl.replace("-1", "");
	   ajaxUrl = ajaxUrl.replace("-2", "");
	   ajaxUrl = ajaxUrl.replace("-3", "");
	   ajaxUrl = ajaxUrl.replace("-4", "");
	   ajaxUrl = ajaxUrl.replace("-5", "");
	   
	    var options = {
            target: "#"+that.id.replace("-form", ""),
			url: ajaxUrl,   
            clearForm: true        // clear all form fields after successful submit 
            //resetForm: true      // reset the form after successful submit 
        };
        
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(that).ajaxSubmit(options);
    }
}

var FeatureList = {
	    selector: "#business-area-content-zone dl.feature-list",
		
	    initFeatureList: function(){
	        $(FeatureList.selector + ' dt').mouseover(function(){
	            $this = $(this);

                //close other opened layer
                FeatureList.clear();

				//open
                $this.addClass("current").next().show();
	        });

	        $(FeatureList.selector).hover(null, function(){
	        	FeatureList.clear();
	        });
	    },

	    clear: function(){
	    	$(FeatureList.selector + ' dd').hide();
	    	$(FeatureList.selector + ' dt').removeClass("current");
	        
	    }
}

