var int_minusClickCount;
//var contentHeight;
//var productCatOn  ;


// event observe OnLoad
Event.observe(window, 'load', page_loaded, false);  


// function page load
function page_loaded(evt) {
	if( $('lightbox') ) { Event.observe('lightbox', 'click', item_clicked, false); }
	if( $('b_SendMail') ) { Event.observe('b_SendMail', 'click', contactUsSubmit, false); }
}


// contact us form OnSubmit // ++++++++++++++++ // start
function contactUsSubmit() {
//alert( 'send mail' );
	// check mail
	var arr_field = new Array( 'sendername', 'senderremail', 'senderphone', 'yourtext' );
	var i_length = arr_field.length ;
	var matchTag = /<(?:.|\s)*?>/g ;
	//
	for( var i=0; i<i_length; i ++ ) {
		var tmpField = eval( 'document.sendmail.'+ arr_field[i] ) ;
		if ( tmpField.value == '' ) {
			var str_tmp = $( 'l_'+ arr_field[i] ).innerHTML ;
			str_tmp = str_tmp.replace(matchTag, "");
			alert( str_pleasefill +' '+ str_tmp );  //$('contactus').elements[i].name
			tmpField.focus() ;
			return false ;
		}
	}

	// process mail
	showLightBox() ;

	// collect data
	var str_arg = '';
	var obj_form = eval('document.sendmail') ;
	var i_length = obj_form.length ;
		for( var i=0; i<i_length; i ++ ) {
			if( str_arg != '' ) { str_arg += '&'; }
			str_arg += obj_form[i].name +'='+ encodeURI(obj_form[i].value) ;
		}

	str_arg += '&langsel='+ str_lang  ;

//alert( str_arg );

	//
	var myReturn = f_ajax( 'http_mailContact.php', str_arg , 'text' );

	// clear data
	obj_form.reset() ;

}
// contact us form OnSubmit // ++++++++++++++++ // end

// all click // +++++++++++++++++ // start
	function item_clicked(evt){
		var child = Event.element(evt);
//alert( child.id ) ;
		if( child.id == 'lightbox_closebutton' || child.id == 'img_lightbox_closebutton' ) {
			hideLightBox() ;
		} else if( child.id.substr(0,3) == 'cat' ) {
			if( $('sub'+ child.id) ) { $('sub'+ child.id).style.display = 'block'; }
			productCatOn = child.id ;
			return ;
		} else if( child.id.type = 'a' ) {
			return ;
		}

		Event.stop(evt); //avoid another call related to 'parent_node' itself
	}
// all click // +++++++++++++++++ // end

// special click // ++++++++++++++++++++++++++++++++++ // start
	function jcChangImage( a_divTargetID, a_sourceImage, a_intWidth, a_intHeight ) {
		if( a_sourceImage != '' ) {
			var obj_img = $(a_divTargetID).getElementsByTagName('img') ;
			obj_img[0].src = a_sourceImage ;
		}
	}
// special click // ++++++++++++++++++++++++++++++++++ // end

// AJAX // ++++++++++++++++++++++++++ // start
	function f_ajax( http_file, str_arg, returnType ) {
		// returnType : responseXML || responseText
		var myAjax = new Ajax.Request( http_file, { 
			method:'post' ,
			parameters: str_arg ,
			onSuccess: function(transport){
				if( returnType == 'text' ) {
					 var response = transport.responseText || "no response text";
					 $('lightBoxContent').innerHTML = response ;
				} else if( returnType == 'xml' ) {
					 var response = transport.responseXML || "no response XML";
					 // check output
					 switch( http_file ) {
						 case 'http_layoutDetail.php' :
							 var myStatus = response.getElementsByTagName('unitStatus') ;
							var myDisplay = response.getElementsByTagName('displayText') ;
							var mySQL = response.getElementsByTagName('sql') ;
							$('lightBoxContent').innerHTML = myDisplay[0].childNodes[0].nodeValue ;
							// $('lightBoxContent').innerHTML += '<br />'+ mySQL[0].childNodes[0].nodeValue ;
							// className
							// if( myStatus[0] > 0 ) { $('lightbox').setAttribute('class', 'sold'); } else { $('lightbox').setAttribute('class', ''); }
							if( myStatus[0] > 0 ) { $('lightbox').className = 'sold'; } else { $('lightbox').className = '' ; }
						 break ;
					 }
				}
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}

	function f_ajaxReturnID( http_file, str_arg, returnType, returnID ) {
		// returnType : responseXML || responseText
		var myAjax = new Ajax.Request( http_file, { 
			method:'post' ,
			parameters: str_arg ,
			onSuccess: function(transport){
				if( returnType == 'text' ) {
					 var response = transport.responseText || "no response text";
					 $( returnID ).innerHTML = response ;
				} else if( returnType == 'xml' ) {
					 var response = transport.responseXML || "no response XML";
					 return response ;
				}
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
// AJAX // ++++++++++++++++++++++++++ // end

// open & close lightBox // ++++++++++++++++++++++ // start

		// showLightBox // ++++++++++++++++++++++++++++++++++ // start
		function showLightBox() {
			var obj_frame = $('lightboxbg') ;
			var obj_detail = $('lightbox') ;

			if( obj_frame ) {
				obj_frame.style.visibility = 'visible';
				obj_frame.style.display = 'block';

				obj_detail.style.visibility = 'visible';
				obj_detail.style.display = 'block';

				if( !document.all ) { 
					obj_frame.style.position = 'fixed'; 
				} else {
					obj_detail.style.position = 'absolute'; 
				}

				//
				////
				bod = document.getElementsByTagName('body')[0];
				bod.style.height = '100%' ;
				bod.style.overflow = 'hidden' ;
		  
				htm = document.getElementsByTagName('html')[0];
				htm.style.height = '100%' ;
				htm.style.overflow = 'hidden' ; 
				////
			}
		}
		// showLightBox // ++++++++++++++++++++++++++++++++++ // end


		// hideLightBox // ++++++++++++++++++++++++++++++++++ // start
		function hideLightBox() {
		
			var obj_frame = $('lightboxbg') ;
			obj_frame.style.visibility = 'hidden';
			obj_frame.style.display = 'none';

			var obj_detail = $('lightbox') ;
			obj_detail.style.visibility = 'hidden';
			obj_detail.style.display = 'none';

			////
			bod = document.getElementsByTagName('body')[0];
			bod.style.height = '100%' ;
			bod.style.overflow = 'auto' ;
		  
			htm = document.getElementsByTagName('html')[0];
			htm.style.height = '100%' ;
			htm.style.overflow = 'auto' ; 
			////
			$('lightBoxContent').innerHTML = 'Processing ...';
			$('lightbox').setAttribute('class', '');
		}
		// hideLightBox // ++++++++++++++++++++++++++++++++++ // end


// open & close lightBox // ++++++++++++++++++++++ // end





	function jc_setFlash( a_file, a_title ) {
		swfobject.embedSWF("player.swf?file="+ a_file +"&aplay=true&autorew=true&title="+ a_title +"", "flashvideo", "195", "140", "7.0.0", "expressInstall.swf", flashvars, params, attributes );
	}


	// cookie // ++++++++++++++++++++++++++++++++++ // start
	// from http://www.quirksmode.org/js/cookies.html //
		function createCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}

		function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}

		function eraseCookie(name) {
			createCookie(name,"",-1);
		}
	// cookie // ++++++++++++++++++++++++++++++++++ // end

	// ajaxCalendar // ++++++++++++++++++++++++++++++ // start
	function ajaxCalendar( a_date ) {
		// a_date : 0000-00-00
		str_arg = 'caldate='+ a_date ;
		str_arg += '&langsel='+ str_lang  ;
		f_ajaxReturnID( 'http_calendar.php', str_arg, 'text', 'subcontent' ) ;
	}
	// ajaxCalendar // ++++++++++++++++++++++++++++++ // end
	
	
	// slide show jcSlide // ++++++++++++++++++++++++++++++++++++ // start
	var slideINDEX = 0 ;
	var slideLength = 0;
	var retnode = [];
	setInterval( "jcSlideShow(  )",  7000 );
	
	function jcSlide( a_group, a_id ) {
		retnode = [];
		var elem = document.getElementsByTagName('img');
		for (var i = 0; i < elem.length; i++) {
			if( elem[i].id.substr(0, 4) == 'gall' ) {
				// group // ++++++++++++ // start
				var arr_group = elem[i].id.split('_') ;
				if( arr_group[1] == a_group ) { 
					retnode.push(elem[i]);
				}
				// group // ++++++++++++ // end
			}
		}
		
		slideLength = retnode.length
		slideINDEX = 0 ;
		
		// process slide show
		clearInterval ( );
		clearTimeout( );
		
		//clearTimeout( );
		//clearInterval ( );
		//setInterval( "jcSlideShow(  )",  7000 );
		//
		//clearTimeout( );
		//setTimeout( "jcSlideShow(  )",  7000 );
	}
	// slide show jcSlide // ++++++++++++++++++++++++++++++++++++ // end
	
	// slide show // +++++++++++++++++++++++++++++ // satrt
	function jcSlideShow(  ) {
		if( slideLength > 0 ) {
			a_divTargetID = 'subcontent';
			var obj_img = $(a_divTargetID).getElementsByTagName('img') ;
			// transition : 1 // +++++++++++++++++++ // start
				// set obj_img[1]
				obj_img[1].src = obj_img[0].src ;
				obj_img[1].width = obj_img[0].width ;
				obj_img[1].height = obj_img[0].height ;
				obj_img[1].style.position = 'absolute';
				obj_img[1].style.top = obj_img[0].style.top ;
				obj_img[1].style.left = obj_img[0].style.left ;
				obj_img[1].style.zIndex = 2000 ;
			// transition : 1 // +++++++++++++++++++ // end
			obj_img[0].src = retnode[slideINDEX].src ;
			slideINDEX += 1 ;
			if( slideINDEX >= slideLength ) { slideINDEX = 0; }
			// transition : 2 : fadeout // +++++++++++++++++++ // start
			// clearInterval(e.ai); e.ai=setInterval(function(){TINY.alpha.tw(e,a,d,s)},20)
				for( var i=0; i<100; i ++ ) {
					obj_img[1].style.opacity = (i / 100);
					obj_img[1].style.MozOpacity = (i / 100);
					obj_img[1].style.KhtmlOpacity = (i / 100);
					obj_img[1].style.filter = "alpha(opacity=" + i + ")"; 
				}
				obj_img[1].style.zIndex = -1000 ;
			// transition : 2 : fadeout // +++++++++++++++++++ // end
		}
	}
	// slide show // +++++++++++++++++++++++++++++ // end