/*
 |™*******************************************************************************************™*
 | jQuery and jQuery Plugin
 |™*******************************************************************************************™*
*/

/*
 |™*******************************************************************************************™*
 | TinyMCE
 |™*******************************************************************************************™*
*/
if (jQuery("#TXAwebboard_detail, #TXAwebboard_reply_detail").length > 0) { // use jQuery("textarea") for all textarea to turn tinymce
	
	tinyMCE.init({
		// General options
		mode: "textareas",
		theme: "advanced",
		editor_selector : "mceEditor",
		editor_deselector : "mceNoEditor",
		skin: "o2k7",
		plugins: "tinyBrowser,advimage, safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		// Theme options
		theme_advanced_buttons1: "newdocument,|,bold,italic,underline,strikethrough,emotions,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect",
		theme_advanced_buttons2: "",
		theme_advanced_buttons3: "",
		//theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",

		theme_advanced_toolbar_location: "top",
		theme_advanced_toolbar_align: "left",
		//theme_advanced_statusbar_location: "bottom",
		//theme_advanced_resizing: true,
		file_browser_callback : "tinyBrowser"
	});
		
}	
/*
 |----------------------------------------------------------------------------------------------
 | Form plugin
 |----------------------------------------------------------------------------------------------
*/
$().ready(function() {

//---------->> click for submit event form Login
	$("#LIKlogin, #LIKlogin_top").click(function() { 

		var form_action = $("form#singin").attr("action"); // get form action
		var link_type = $(this).attr("title"); // get link title
		//var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?auid=" + link_type,
			type: "post"        
		}

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

//---------->> click for submit event form Logout
	$("#LIKlogout").click(function() { 

		var form_action = $("a#LIKlogout").attr("href"); // get form action

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action ,
			type: "post"        
		} 

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

//---------->> attach handler to LINK TAG for Confirm

	$("#LIKconfirm").click(function() { 

		var form_action = "member-history-core.php"; // get form action
		var link_type = $(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&id=" + link_split[2] + "&auid=" + link_split[3],
			type: "post"        
		}
		
		// submit the form 
		$().ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
		
//---------->> attach handler to LINK TAG for submit event

	$("#LIKsave, #LIKsend, #LIKedit").click(function() { 

		var form_action = $("form").attr("action"); // get form action
		var link_type = $(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2],
			type: "post"        
		}
		
		// submit the form 
		$("form").ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});

//---------->> click for add cart

	$(".bt-cart").click(function() { 

		var form_action = "shopping-core.php"; // get form action
		var link_type = $(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2] + 
				 "&type=" + link_split[3] + "&class=" + link_split[4] + "&id=" + link_split[5] + "&name=" + link_split[6] + 
				 "&size=" + link_split[7] + "&qty=" + link_split[8],
			type: "get"        
		}
		
		// submit the form 
		$().ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});

//---------->> click for delete

	$(".LIKdelete").click(function() { 

		var form_action = "shopping-core.php"; // get form action
		var link_type = $(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2] + 
				 "&id=" + link_split[3],
			type: "get"        
		}
		
		// submit the form 
		$().ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
	
//---------->> attach handler to SUBMIT TAG for submit event

	$("form").submit(function() { 
	
		var form_action = $(this).attr("action"); // get form action
		var link_type = $(this).attr("title"); // get link title
		var link_split = link_type.split(":"); // split link title

		var options = {
			//dataType: "html", // FOR DEBUG: when download file not return error
			dataType: "json",
			beforeSubmit: showRequest,
			success: showResponse,
			// !!! insert ?token=xxx in file add, edit form !!!
			url: form_action + "?module=" + link_split[0] + "&action=" + link_split[1] + "&auid=" + link_split[2],
			type: "post"       
		}
		
		// submit the form 
		$(this).ajaxSubmit(options); 
		
		// return false to prevent normal browser submit and page navigation 
		return false; 
		
	});
	

});

/*
 |™*******************************************************************************************™*
 | 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() {
				$("form").resetForm();
				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();
	
}

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

/*
 |----------------------------------------------------------------------------------------------
*/

/*
 |----------------------------------------------------------------------------------------------
 | Dropdown Menu Jump
 |----------------------------------------------------------------------------------------------
*/
$().ready(function() {

	$("#SELmonth, #SELyear").change(function() {
						  
		if ($(this).val() != "") {							
			window.location = $(this).val();
		}
		
	});

});

/*
 |----------------------------------------------------------------------------------------------
 | [Check Change password]
 |----------------------------------------------------------------------------------------------
*/

$("#CHKchange").click(function () {							  
  if(this.checked){
	$("#change").css("display","inline-block");
  }else{
	$("#change").css("display","none");
  }
});

/*
 |----------------------------------------------------------------------------------------------
 | 								                   	     jQuery Plugin Pretty Photo - 27-02-2010 
 |----------------------------------------------------------------------------------------------
*/
/* jQuery Plugin Pretty Photo 
$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
});
*/

/* jQuery Plugin Pretty Photo */
$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});

/*
 |----------------------------------------------------------------------------------------------
 | 							      jQuery Plugin Sliding Menu ( Categories Gallery ) - 27-02-2010
 |----------------------------------------------------------------------------------------------
*/		
$('img.ct-gallery_class').click(function () {
$('ul.the_ct-gallery').slideToggle('medium');
});

/*
 |----------------------------------------------------------------------------------------------
 | 							        jQuery Plugin Sliding Menu ( Categories Story ) - 03-03-2010
 |----------------------------------------------------------------------------------------------
*/		
$('img.ct-story_class').click(function () {
$('ul.the_ct-story').slideToggle('medium');
});

/*
 |----------------------------------------------------------------------------------------------
 | 									            jQuery Plugin Sliding Menu ( Menu ) - 28-02-2010
 |----------------------------------------------------------------------------------------------
*/		
$('img.menu_class').click(function () {
$('ul.the_menu').slideToggle('medium');
});

/*
 |----------------------------------------------------------------------------------------------
 | 									          jQuery Plugin Sliding Menu ( Option ) - 02-03-2010
 |----------------------------------------------------------------------------------------------
*/		
$('img.option_class').click(function () {
$('ul.the_option').slideToggle('medium');
});

/*
 |----------------------------------------------------------------------------------------------
 | 									            jQuery Plugin Slider Menu ( Login ) - 28-02-2010
 |----------------------------------------------------------------------------------------------
*/		
$(".topMenuAction").click( function() {
	if ($("#openCloseIdentifier").is(":hidden")) {
		$("#slider").animate({ 
			marginTop: "-94px"
			}, 500 );
		$("#topMenuImage").html('<img src="./images/slider/open.png" alt="open" />');
		$("#openCloseIdentifier").show();
	} else {
		$("#slider").animate({ 
			marginTop: "-122px"
			}, 500 );
		$("#topMenuImage").html('<img src="./images/slider/close.png" alt="close" />');
		$("#openCloseIdentifier").hide();
	}
});  

/*
 |----------------------------------------------------------------------------------------------
 | 								                        jQuery Plugin Simple Toggle - 02-03-2010 
 |----------------------------------------------------------------------------------------------
*/
$(".toggle_container").hide();

$("h2.trigger").toggle(function(){
	$(this).addClass("active"); 
	}, function () {
	$(this).removeClass("active");
});

$("h2.trigger").click(function(){
	$(this).next(".toggle_container").slideToggle("slow,");
});


/*
 |----------------------------------------------------------------------------------------------
 | 								                   	    jQuery Plugin  jqTransform  - 28-04-2010 
 |----------------------------------------------------------------------------------------------
*/
$(function(){
	$('form#searchbox').jqTransform({imgPath:'jqtransformplugin/img/'});
});



/*
 |™*******************************************************************************************™*
 | 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
		}
	});


        