var mylook={
	secondaryMenu:function(){
			var a=$(".secondary-menu ul li");
			a.mouseover(function(){
				$(this).addClass("hover")
			}).mouseout(function(){
				$(this).removeClass("hover")
			})
	},
	sliderH:function(){
		function c(){
			var b=$(this).parent();
			if(!b.hasClass("active")){
					var c=$("#third-level .active");
					b.css("width",b.width);
					a.removeClass("active");
					$(c).animate({width:79},400,function(){});
					b.animate({width:440},400,function(){$(b).addClass("active")})
			}
		}
		var a=$("#third-level .item");
		a.css("width",79);
		$("#third-level .active").css("width",440);
		var b={over:c,timeout:500,out:function(){}};
		a.find(".header").hoverIntent(b)
	},
	carousel:function(){
		$(".carousel-wrap").before('<div id="nav">').cycle({fx:"fade",timeout:8000,pagerEvent:"click",pager:"#nav"}).removeAttr("style");
		$("#carousel #nav a").text("")
	},
	checkbox:{
		mkstyle:function(){
			$(".CheckBoxLabelClass").click(function(a){
				a.preventDefault();
				if($(this).hasClass("LabelSelected")){
					$(this).prev().attr("checked",false);
					$(this).removeClass("LabelSelected")
				}else{
					$(this).addClass("LabelSelected")
					$(this).prev().attr("checked",true);
				}
			})
		},
		init:function(){
			this.mkstyle()
		}
	},
	dropdown:{
		mkstyle:function(){
			$(".dropdown").each(function(){ 
				$(this).jqDropDown({
					defaultStyle:false,
					toggleBtnName:"toggleBtnName",
					optionListName:"optionList",
					modal: true,
					optionChanged : function(ele){
						$(ele).parent().parent().find('li a').removeClass('selected');
						$(ele).addClass('selected');						
					},
					placeholder:"frmSignUp",
					beforeToggle:function(){
						$(this).next(".optionList").find("li:last-child").css("border-bottom","none")
					}
				})
			})
		},
		init:function(){
			this.mkstyle()
		}
	},
	form: {
		valid : false,
		init: function(){
			
			
			mylook.form.formEle = $('form');
			mylook.form.formEle.find('.require').val('');
			mylook.form.validate.onFocus();
			
			mylook.form.formEle.find('.optionList li a').removeClass('selected');
			mylook.form.formEle.find('.optionList li:first-child a').addClass('selected');
			
			$("form #btn_submit").click(function(e){
				e.preventDefault();
				mylook.form.validate.init();
				
				if (mylook.form.valid){
					$('form#frm').submit();
				}
				
			})
		},
		validate: { 
			focus: false,			
			init : function() {
				
				mylook.form.valid = true;				
				var frmEle = mylook.form.formEle.find('.require');				
				
				frmEle.each(function() {
					mylook.form.validate.textbox($(this));										
				});									
				
				mylook.form.validate.checkbox();
				mylook.form.validate.dropdown();
				
				if (mylook.form.formEle.find('.error').length > 0){
					mylook.form.valid = false;					
				} else {
					mylook.form.valid = true;
				}												
			},
			textbox: function(ele){
				
				if (ele.val().length < 1) {					
					mylook.form.validate.showError(ele,'* type something');								
				}
				else if (ele.hasClass('email') && !ele.hasClass('error'))
				{						
					ele.attr('value-typed', ele.val());
					if (!mylook.form.validate.checkemail(ele.val())) {														
						mylook.form.validate.showError(ele, '* invalid email');										
					}	
				} 					
					
			},
			dropdown: function(){
				
				if ($('form #dp_country .optionList .selected').attr('rel') == "default") {
					mylook.form.validate.showError(null,'* please select your country', true);					
				}
				
				if ($('form #dp_days .optionList .selected').attr('rel') == "default") {
					mylook.form.validate.showError(null,'* please select your best time day', true);					
				}
				
				if ($('form #dp_time .optionList .selected').attr('rel')== "default") {
					mylook.form.validate.showError(null,'* please select your best eastern time', true);					
				}
				
				
			},
			checkbox: function(){
				var cont = 0;
				
				var panel = $('form .panel-errors');
				panel.find('span').html('');
				panel.hide();
				
				$('form #area .CheckBoxLabelClass').each(function(){
					var _this = $(this);
					if (_this.hasClass('LabelSelected') == true) {					
						cont++;	
					}					
				})	
				
				if (cont == 0){
					mylook.form.validate.showError(null,'* please select almost one area you are interested in enhancing.', true);										
				}
				
				cont = 0;
				$('form #procedure .CheckBoxLabelClass').each(function(){
					var _this = $(this);
					if (_this.hasClass('LabelSelected') == true) {					
						cont++;	
					}
				})
										
				if (cont == 0){
					mylook.form.validate.showError(null,'* please select almost one procedure you are interested in.', true);										
				}
			},
			onFocus: function(){
				mylook.form.formEle.find('.require').focusin(function(){
				
					var ele = $(this);					
					if (ele.hasClass('error')) {
						ele.removeClass('error').val('');						   
					}					
					if (ele.attr('value-typed')){
						if (ele.attr('value-typed').length > 0){
							ele.val(ele.attr('value-typed'));
						}					
					}	
				});				
			},
			checkemail : function(value){
				if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
					return true;
				}else{
					return false;
				}
			},
			showError :  function(ele, message, panel){
				if (panel == true){
					var panel = $('form .panel-errors');
					panel.find('span').append('<p>'+ message +'</p>');
					panel.show();
				}else{
					$(ele).addClass('error').val(message);				   				
				}
				mylook.form.valid = false;			
			}				
		}	
	},
	nav: {
		init:  function(){			
			$("nav ul li.submenu").hoverIntent(function(){
				$(this).addClass('hover');
			},						
			function(){
				$(this).removeClass('hover');
			});		
		}		
	},
	init:function(){
			this.dropdown.init();
			this.checkbox.init();
			this.sliderH();
			this.secondaryMenu();
			this.form.init();
			this.nav.init();
			if ($("#carousel").length > 0) { 
				this.carousel();
			}	
	}
};

$(document).ready(function(){
	mylook.init();
	
	if ($("#datepicker").length > 0) { 
		$("#datepicker").datepicker({
	     	minDate: new Date(2011, 0, 1),
	        dateFormat: 'mm/dd/yy',
	        constrainInput: true
		})	
	}
	
})
