// JavaScript Document
var num;
var index=1;

jQuery(document).ready(function() {
   num=jQuery('#mycarousel li').length;
   changeControlImg(index)
    jQuery('#mycarousel').jcarousel({
	     wrap: 'first',
		// auto: 3,
	    initCallback: mycarousel_initCallback,		 
        //itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        //itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
        scroll: 1
		
    });
	
	//
	
	
});
function mycarousel_initCallback(carousel) {

   //alert("ddd");
   
   jQuery("#wrap").bind("mouseenter",function()
	{
	
	//carousel.options.auto=0;
	//carousel.stopAuto();
	
	
	}
	);
	jQuery("#wrap").bind("mouseleave",function()
	{
	
	 // carousel.options.auto=3;
	 // carousel.startAuto();
	}
	);
    //prev
	jQuery('#prevImg').bind('click', function() {
	    //index=jQuery(this).attr("title")-1;
		  
		if(index==1)
		{
		    //alert("prev end");	
			
			return;
			}
		  index=index-1;
		 
		 changeControlImg(index)
		  //alert(index);
		 var curObj=carousel.get(index);
		 $("#changeTitle").html(curObj.attr("name"));
		carousel.prev();
		//carousel.scroll(jQuery.jcarousel.intval(index));
		//changeImage();
		
		//
		//
		 });
		 jQuery('#nextImg').bind('click', function() {
			 if(index==num)
			 {
				 //alert("end");
				 return;
				 }
		index=index+1;
		
		changeControlImg(index)
	    //alert(index);
		var curObj=carousel.get(index);
		 $("#changeTitle").html(curObj.attr("name"));
		//index=jQuery(this).attr("title")-1;
		carousel.next();
		
		//carousel.scroll(jQuery.jcarousel.intval(index));
		//changeImage();
		
		//
		//
		 });
	//next
    //
     jQuery('.page').bind('click', function() {
	    index=jQuery(this).attr("title")-1;
		
		carousel.scroll(jQuery.jcarousel.intval(index));
		changeImage();
		
		//
		//
		 });
		
	 return false;
	
	   

}

function changeImage()
{
   // alert(index);
    $(".page").each(function()
	{
	     var title=jQuery(this).attr("title");
		 if(title==index)
		 {
		     $(".page").html("<img src='"+dir+"images_en/point2.jpg' border='0'>");
			 $(this).html("<img src='"+dir+"images_en/point.jpg' border='0'>");
			 //
			 $("#changeTitle").html($(this).attr("name"));
		 }
	}
	);
}
function changeControlImg(index)
{
	if(index==1)
		 {
			 jQuery('#prevImg').attr("src",""+dir+"images_en/arrow-left2.jpg");
			 }else
			 { jQuery('#prevImg').attr("src",""+dir+"images_en/arrow-left.jpg");
				 }
	 if(index==num)
		 {
			 jQuery('#nextImg').attr("src",""+dir+"images_en/arrow-right2.jpg");
			 }else
			 { jQuery('#nextImg').attr("src",""+dir+"images_en/arrow-right.jpg");
				 }
	
	}
//
/*function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{    
    
     index++;
	 if(index>num)
	 index=1;
      changeImage();
   var classname='#data-li'+index;
  //
	 
  // var classname='#mycarousel-'+index;
	var html= jQuery(classname).html();
	//alert(i);
	carousel.add(i,html);
	
}

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{ 
//alert($(".mycarousel li").length);
    if($("#mycarousel li").length>num)
     {
		
		 carousel.remove(i);}
}*/


