(function($) {
	var BgHandler = window.BgHandler = function() {
		var LangType = {
			ENG: '0',	// English 
			ES: '1'		// Spanish
		};
		
		// default options which is not changed by parameter passed by users
		var defs = defaults = {
			homeStyle: "3", 		//HomeStyle 3 - Zen, 2 - Portal, 1 - Classic
			lang: "0",     
			bgImg: "",			//Background Image
			bmh: 15,  			//Bottom Margin Height
			bdw: 958,			//Browser Default Width
			bdh: 530,			//Browser Default Height
			logoLeft:0,			//LogoLeft
			logoTop:0,			//LogoTop
			adImg: "",			//Advertise with us
			adHoverImg: "",		//Advertise with us hover image
			impId: ""
		};

		var init = function(opts) {
			defs = $.extend(defaults, opts);			
			if (defs.lang == null || defs.lang == '') defs.lang = 0;
			
			switch (defs.homeStyle) {
				case "3":
					$(window).bind("load", loadBg);
					$(window).bind("resize", resizeBg);
					
					$('#imgDiv').mouseover(function(){                
		         		$('#imgDescDiv').css("overflow","visible");
		         		$('#imgDescDiv').css("visibility","visible");
		         		$('#imgDescDiv').css("width","auto");
		    		});
		
					$('#imgDescDiv').mouseout(function(){                
		         		$('#imgDescDiv').css("overflow","hidden");
		         		$('#imgDescDiv').css("visibility","hidden");
		         		$('#imgDescDiv').css("width","10px");
		    		});	
					
    				//Detect Chrome/Safari and change the Styles
    				if ($.browser.webkit) {
    					$("#form_ps #l_firstname").css({"left":10+"px", "width":150+"px"});
    					$("#form_ps #l_lastname").css({"left":-143+"px", "width":150+"px"});
    					$("#form_rl #l_tel").css({"left":6+"px", "width":200+"px"});
    					$("#form_cs #l_what").css({"left":6+"px", "width":150+"px"});
    				}
    				
    				$("#advertiseWithUs").mouseover(function(){
    					$("#advertiseWithUs").attr("src", defs.adHoverImg);
    				});
    				
    				$("#advertiseWithUs").mouseout(function(){
    					$("#advertiseWithUs").attr("src", defs.adImg);
    				});
    				
		    	break;
		    case "2":
		    	break;
		    case "1":
		    	break;
		    }
		};
				
		var resizeBg = function() {			
			var bg = $("#bgDiv2");
			var cw = $("#cp_wrapper");
			var cf = $(".cp_sform");

    		var w = $(window).width();
    		var h = $(window).height();
    		var mg = cf.height()/2;		    		    
			
    		var ir = defs.bdw / defs.bdh;
    		var vr = w / h;		
    
    		/*if (h<600) {
    			jQuery("#footer").css("display","none");
    			BOTTOM_HEIGHT = 0; 	
    		}
    		else {
    			jQuery("#footer").css("display","block");
    			BOTTOM_HEIGHT = 15;
    		}*/
    
    		cw.css({"top": (h/2)-mg-defaults.bmh+"px", "width": w});
			if (vr > ir) {
				bg.width(w + "px").height((w / ir) + "px");
			}
    		else {
    			bg.width((h * ir) + "px").height(h+defaults.bmh + "px");
    		}	
			
			if (defs.impId == '1' || defs.impId == '25' || defs.impId == '44') {
				setZipDealImagePos();
			}
			
			if ($.browser.msie && $.browser.version == '6.0') {
				MenuSwitch.showIE6Message();
			}
		}
		
		var changeBgSrc = function() {
			$("#bgDiv2").attr("src", defs.bgImg).delay(1000).fadeIn(1000);
		}
		
		var loadBg = function() {
			resizeBg();
			changeBgSrc();
		}
		
		var setZipDealImagePos = function() {
			defs.logoLeft = $("#logo").offset().left;
			defs.logoTop = $("#logo").offset().top;
			var topMargin = 24;
			var leftMargin = 655;
			if (defs.impId==25) {
				topMargin = 16;
				leftMargin = 660;
			}
			$("#zipdeal").css({ position: "absolute",
            	   		    	   	 top: defs.logoTop-topMargin, 
            	   			     	left: defs.logoLeft+leftMargin});
		}
		
		return {
			init:init
		};
	}();
})(jQuery);

