// JavaScript Document
jQuery(document).ready(function() {
	var isAddCaruosel = false;
	var imgObj = new Image();
	var tempwidth = 0;
	
	jQuery("a.UpDown").bind("click",function() {
		if(!jQuery(this).hasClass("Active") && !jQuery(this).hasClass("Display")){
			if($("a.UpDown.Active").length > 0 && !jQuery(this).hasClass("SpecialUpDown")) {
				jQuery("a.UpDown.Active").parent().next().slideUp();
				jQuery("a.UpDown.Active").removeClass("Active");
			}
			
			jQuery(this).addClass("Active");
			jQuery(this).parent().next().slideDown();
			//jQuery(this).parent().scrollTop(300);
		}	
		else if(jQuery(this).hasClass("Active")) {	
			jQuery(this).removeClass("Active");
			jQuery(this).parent().next().slideUp();	
		}
	});
	jQuery("a.UpDown").bind("click",function() {
		 if(jQuery(this).parent().parent('.Info02').hasClass("Info02_active")){
			jQuery(this).parent().parent('.Info02').removeClass('Info02_active');
		 }
		 else{
			jQuery("div.Info02").removeClass('Info02_active');
			jQuery(this).parent().parent('.Info02').addClass('Info02_active');
		 }
	});
	
	// Add carousel when slidedown
	jQuery(".CarouselOpen").bind("click",function() {
			if($(".CarouselArea").length > 0 && !isAddCaruosel){
				isAddCaruosel = true;
				if(jQuery(this).find(".jcarousel-container").length==0){
				jQuery(this).parent().next().find(".Carousel").jcarousel({
					scroll:1,
					wrap: 'circular',
					itemVisibleInCallback: itemVisibleInCallbackFunction,
					auto:5,
					animation: 0
				}); 
			}
			//end
			}									  
	});
	
	if($(".AutoTooltip").length > 0) {
		jQuery(".AutoTooltip").tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " _ ",
			top: -10,
			left: 20
		});
	}
	
	//open popin when lick on carousel
	if(jQuery(".CarouselZoomImg").length > 0) {
		jQuery(".CarouselZoomImg").bind("click",function() {
			var tempImg = new Image();
			tempImg.src = this.rel;
			tempImg.title =  jQuery(".CarouselZoomImg").parent().find("#titlePopup").html();
			jQuery(".SpecialPopup .TableCellContent").html(tempImg);
			// document.getElementById('titlePopup2').innerHTML = tempImg.title;
		});
	}




function itemVisibleInCallbackFunction(carousel, state, evt)
{
	//fix bug did not show image
	if( carousel.container.find("#mycarousel02").width() == 0) {
		carousel.container.find("#mycarousel02").width(tempwidth);
	}
	else{
		tempwidth = carousel.container.find("#mycarousel02").width();
	}
	//
		var liObj = carousel.get(carousel.last);
		var img = liObj.children();
	    var imgSrc = img.attr("rel");
		var imgWidth = img.attr("width");
		var imgHeight = img.attr("height");
		var imgTitle = img.attr("title");
		imgObj.src = imgSrc;
		imgObj.title = imgTitle;
		carousel.buttonNext.parent().parent().parent().parent().parent().parent().find('.CarouselZoomImg').attr("rel",imgSrc);
		carousel.buttonNext.parent().parent().parent().parent().parent().parent().find('#titlePopup').html(imgTitle);
};
});

function ReAddCarousel(){
	if(jQuery("#mycarousel02").length > 0) {
		$(".Info02Content").slideDown();
		var alink = jQuery("a.UpDown");
		if(alink.find(".jcarousel-container").length==0){
					alink.next().find(".Carousel").jcarousel({
						scroll:1,
						wrap: 'circular',
						auto:5
					});
		}
	}
}



