

$(function(){

	// Global Element
	$("a").each( function() {
		if ($(this).attr("href") == undefined || $(this).attr("href") == "#" || $(this).attr("href") == "") {
			if ( $(this).parent().parent().parent().attr("id") != "menu" ) {
				$(this).attr({href:"#"});
				//$(this).css("cursor", "default");
				$(this).click( function(e) { e.preventDefault(); });
			}
		}
		$(this).focus( function() { $(this).blur(); });
	});
	$("input[type=submit], input[type=reset], input[type=button], input[type=select], input[type=image], input[type=radio], input[type=checkbox]" ).each( function() {
		$(this).focus( function() { $(this).blur(); });
	});

	// handle select text
	$("input[type=text], textarea").each( function() {
			if ( $(this).hasClass("username") || $(this).hasClass("number") || $(this).hasClass("amount") ) {
				$(this).attr("autoComplete", "Off");
			}
			$(this).focus( function() {
				$(this).select();
				if ( !$(this).hasClass("focus") ) $(this).addClass("focus");
			});

			if( $(this).hasClass("username") ) {
				$(this).blur( function() {
					$(this).val( clean_whitespace($(this).val()) );
					$(this).removeClass("focus");
				});
			} else {
				$(this).blur( function() {
					$(this).val( jQuery.trim( $(this).val() ) );
					$(this).removeClass("focus");
				});
			}
	});
	$("input[type=password]", this).each( function() {
		$(this).focus( function() {
			$(this).select();
			if ( !$(this).hasClass("focus") ) $(this).addClass("focus");
		});
		$(this).blur( function() {
			$(this).removeClass("focus");
		});
	});

	// Menu Top
	//$("div#topMenu ul.sf-menu").superfish();

    // Jump Page
    if ( $("select#page_jump").length > 0 ) {
        $("select#page_jump").change(function(){
            var meta = $("select#page_jump").metadata();
            self.location.href = meta.baseUrl + '&Start=' + $("select#page_jump :selected").val();
        });
    }
    if ( $("select#page_jump2").length > 0 ) {
        $("select#page_jump2").change(function(){
            var meta = $("select#page_jump2").metadata();
            self.location.href = meta.baseUrl + '&Start=' + $("select#page_jump2 :selected").val();
        });
    }
    
	// Flash
	$("div.flash").each(function(){

		var meta = $(this).metadata();
		meta.wmode = ( meta.wmode != undefined ?meta.wmode :  "opaque" ); // opaque, transparent;

		$(this).flash({
			src: meta.swf, width: meta.width, height: meta.height,
			wmode: meta.wmode, menu: "false",
			flashvars: { dxml: meta.flashvars.dxml }
		});
	});

	// Image Rotation
	if ( $.isFunction($.innerfade) ) {
		$("ul.rotation").each(function(){
			var meta = $(this).metadata();
			meta.type = ( meta.type || "sequence");
			meta.height = parseInt( meta.height || "350") + "px";

			$(this).innerfade({
				speed: 1000,
				timeout: 5000,
				type: "sequence",
				containerheight: '348px'
			});
		});
	}
	// Product Rotation
	if ( $.isFunction($.innerfade) ) {
		$("ul.productRotation").each(function(){
			var meta = $(this).metadata();
			meta.type = ( meta.type || "sequence");
			meta.height = parseInt( "265") + "px";

			$(this).innerfade({
				speed: 1000,
				timeout: 5000,
				type: "sequence",
				containerheight: '265'
			});
		});
	}
	
	// Dropdown choose language
	$('#lang').msDropDown();

});
