/*
 |™*******************************************************************************************™*
 | Using jQuery and jQuery plugin
 |™*******************************************************************************************™*
*/
/*
 |----------------------------------------------------------------------------------------------
 | Swap Image Rollover
 |----------------------------------------------------------------------------------------------
*/
$().ready(function() {
		   
	$(".rollover").hover(function() {
								  
		var currentImg = $(this).attr("src");
		$(this).attr("src", $(this).attr("hover"));
		$(this).attr("hover", currentImg);
		
	}, function() {
		
		var currentImg = $(this).attr("src");
		$(this).attr("src", $(this).attr("hover"));
		$(this).attr("hover", currentImg);
		
	});
	
});

/*
 |----------------------------------------------------------------------------------------------
 | Drop Shadow plugin
 |----------------------------------------------------------------------------------------------
*/
$().ready(function() {
	
  //$(".dropshadow").dropShadow({left: 2, top: 2});

});

/*
 |™*******************************************************************************************™*
 | From Plugin
 |™*******************************************************************************************™*
*/
$().ready(function() {

//---------->> attach link to form for submit event

	$(".StoryTitleLink").bind("click", function() {

			var options = {
				dataType: "html",
				target: '#story_result',
				url:  $(this).attr("href") + "&t=" + new Date().getTime() + Math.random(),        
        		type: "get",  
				beforeSubmit: showRequest,
				success: showResponseStory
			}
	
			// submit the form 
			$(this).ajaxSubmit(options); 
			
			// return false to prevent normal browser submit and page navigation 
			return false; 
			
	});

//---------->> attach handler to form for submit event

	$("form").submit(function() { 
							  
		var options = {
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse
		}

		// submit the form 
		$(this).ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
	
});

/*
 |™*******************************************************************************************™*
 | Index Page
 |™*******************************************************************************************™*
*/
//  

//---------->> Defaule Value !!! Do not place this code in $().ready !!!

$("#TXTmmb_username").DefaultValue("Username :");
$("#TXTmmb_password").DefaultValue("Password :");

//<<----------

$().ready(function() {

//---------->> Banner

	$(window).bind("load", function() { 
		$("div#mygalone").slideView();
	});

//---------->> Slide Photo

	var simpleshow = $("#simpleshow").simpleshow({ speed: 5000, fadeSpeed: 5000 });
	simpleshow.start();

//---------->> Scroller Photo

	$("#scroller").simplyScroll({
		autoMode: 'loop',
		frameRate: 100 
	});

});

/*
 |™*******************************************************************************************™*
 | Create Free WEB Site Menu Page
 |™*******************************************************************************************™*
*/
$().ready(function() {

//---------->> Restrict Only Numeric

	$("#TXTmmb_telephone").numeric();
	$("#TXTmmb_zipcode").numeric();
	$("#TXTmmb_income").numeric(".");

	
//---------->> Immediate Show Image when Change Listbox

	$("#SELmmb_template").bind("change", function() {
												  
		var src = $("#SELmmb_template :selected").text();
		//var src_split = src.split("."); // split template file name exculude extension file

		if(src != "") {
			var img = $("<img src='./upload/" + src + "' />");
			$("#img_dialog").empty().append(img);
			
			$.blockUI({ 
				message: $("#img_dialog"), // set id img_dialog to display none
				overlayCSS: {backgroundColor: "#000", opacity: "0.6"}, 
				css: {
					top: ($(window).height() - 350) / 2 + "px", 
					left: ($(window).width() - 500) / 2 + "px", 
					width: "450px" 
				}	
			}); 
 
        	$(".blockOverlay").click($.unblockUI); 			
		}
		
	});

//---------->> Add Domain Slot
	// send value from package page
	if ($("#SELmmb_package").val() == "2") { // 2 is id for commerce package
		$("<div id='DIVdomain' class='RegisLine'><div class='RegisTitle'>*Domain : </div><div class='RegisInput'><input id='TXTmmb_domain' name='TXTmmb_domain' type='text' class='InputForm' value='' /></div></div>").insertBefore("#addSlotArea");
	} else if ($("#SELmmb_package").val() == "1") {
		$("#DIVdomain").remove();
	}
	
	// onchange in package
    $("#SELmmb_package").change(function () { 
		if ($(this).val() == "2") { // 2 is id for commerce package
			$("<div id='DIVdomain' class='RegisLine'><div class='RegisTitle'>*Domain : </div><div class='RegisInput'><input id='TXTmmb_domain' name='TXTmmb_domain' type='text' class='InputForm' value='' /></div></div>").insertBefore("#addSlotArea");
		} else {
			$("#DIVdomain").remove();
		}
    });

});


/*
 |™*******************************************************************************************™*
 | Contact US Menu Page
 |™*******************************************************************************************™*
*/
//---------->> Defaule Value !!! Do not place this code in $().ready !!!

	$("#TXTcta_name").DefaultValue("Name :");
	$("#TXTcta_email").DefaultValue("Email :");
	$("#TXTcta_telephone").DefaultValue("Telephone :");
	$("#TXActa_detail").DefaultValue("Detail :");
	
//<<----------

/*
 |™*******************************************************************************************™*
 | Function
 |™*******************************************************************************************™*
*/
/*
 |----------------------------------------------------------------------------------------------
 | beforeSubmit Function
 |----------------------------------------------------------------------------------------------
*/
function showRequest(formData, jqForm, options) {

	// blockUI plugin
	$.blockUI({
		message: "<div id='divLoading'>Please wait ...</div>",
		css: { 
			border: "none", 
			padding: "15px", 
			backgroundColor: "#000000", "-webkit-border-radius": "10px", "-moz-border-radius": "10px", 
			opacity: "0.5", 
			color: "#ffffff" 
		}
	});
	
}

/*
 |----------------------------------------------------------------------------------------------
 | Success Function
 |----------------------------------------------------------------------------------------------
*/
function showResponse(responseText, statusText) {

 
 	// for debug ajax form plugin (when use upload file) change option dataType = html
 	//alert("status: " + statusText + "\n\nresponseText: \n" + responseText); return false;

	$.each(responseText, function(key, value) { // json format
								  
		if (key == "SUCCESS") {
			$.prompt(value, { buttons: { }, top: "40%" });
		} else if (key == "UNSUCCESS") {
			$.prompt(value, { buttons: { OK: true }, top: "40%" });
		} else if (key == "REDIRECT") {
			$(this).delay(1000, function() {
				window.location.href = decodeURIComponent(value);
			});
		} else {
			value = value + "<input type='hidden' id='focusfield' name='focusfield' value='" + key + "' />";
			$.prompt(value, { buttons: { OK: true }, top: "40%", callback: focusField });
		}
		
	});
	
	$.unblockUI();
	
}

/*
 |----------------------------------------------------------------------------------------------
*/
function focusField(v, m, f) {
	
	$("#" + f.focusfield).focus().select(); // focusfield is a name of hidden field
	  
}

/*
 |----------------------------------------------------------------------------------------------
*/
function showResponseStory(responseText, statusText) {

	$("#story_result").html(responseText);
	$.unblockUI();
	
}

/*
 |™*******************************************************************************************™*
 | Highslide JS
 |™*******************************************************************************************™*
*/
	hs.graphicsDir = "./libraries/highslide/graphics/";
	hs.align = "center";
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'rounded-white';
	hs.fadeInOut = false;
	//hs.dimmingOpacity = 0.75;
			
	// add the controlbar
	hs.addSlideshow({
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: "fit",
		overlayOptions: {
			opacity: .75,
			position: "bottom center",
			hideOnMouseOut: true
		}
	});

/*
 |™*******************************************************************************************™*
 | FOR PROTOTYPE
 |™*******************************************************************************************™*
*/
/*
 |----------------------------------------------------------------------------------------------
 | Guestbook Menu
 |----------------------------------------------------------------------------------------------
*/
//---------->> Defaule Value !!! Do not place this code in $().ready !!!

	$("#TXTgbk_name").DefaultValue("Name :");
	$("#TXAgbk_detail").DefaultValue("Detail :");
	
//<<----------

/*
|™*******************************************************************************************™*
*/

