/*
 object oriented gallery 
*/
var interval = 4000;
var scroll = 200; 
var no = 0;
options = {
	container: '.img_container',
	arrow: '#arrow',
	navigator: '#navigator'
};

var gallery = function(options){
	var options = options;
	var container = $(options.container);
	var event = this;
	/*
	* Construct image navigator and the others
	*/
	this.construct = function(){
        
        for(i=0;i<container.length;i++){
			event.navigate_id($(container[i]));            
		}
	}
	
	/*
	* Animate item by id using this function
	*/
	
	this.current = function(target){
		images = target.children();
		var c;
        alert(images.length);
        for(i=0;i<images.length;i++){
			if($(images[i]).css('display') == 'block'){
				c = i;
			}
		}
        //alert(c);
		return c;
	}

    
	this.navigate_id = function(target)
    {
		images = target.children().children();        
		var current = 0;
        
		target.children().css({width:target.width()*images.length+'px'});
    /*            
		setInterval(fitem,interval);        
        
		function fitem(){
           
			if(target.scrollLeft() == target.children().width()-(754*no)){			    
                //alert('a');
                target.animate({scrollLeft:0});
			}else{
                //alert('b');                
			    target.animate({scrollLeft:"+="+target.width()*no},200);
            
			}
		}
        */
		//alert(target.width()*images.length+'px');
	}
	
	this.construct();
}

next_img = function(target) 
{
 
		$("#content2").animate({"margin-left": "-=0px"}, 1);

        //no = 1;
		//alert(target.scrollLeft());
        //alert(target.children().width()-(2262*no));
        if(target.scrollLeft() == target.children().width()-(2262*no))
        {                
            target.animate({scrollLeft:0});
        }else{
            target.animate({scrollLeft:"+="+target.width()*no},200);
			//alert("+="+target.width()*no);
        }
}

prev_img = function(target) 
{
	    //target.animate({scrollLeft:2262});
		$("#content2").animate({"margin-left": "-=0px"}, 1);
        if(target.scrollLeft() == 0)
        {                
		//alert('1');
            target.animate({scrollLeft:target.children().width()-2262});
        }else{
            target.animate({scrollLeft:"-="+target.width()*no},200);
			//alert('2');
        }
}

$(document).ready(function(){
    
	gallery(options);
	
    $(".img_container, .test").mouseenter(function(){
           // $('#msgBox').show();
            //alert('in');
            no=0;                 
    })
    $(".img_container , .test").mouseout(function(){
       // $('#msgBox').hide();
        //alert('out');
        no=1;
    })
    
});
