
var jq = jQuery.noConflict();

			jq(function() {


	if(jq('.managecontainer').length > 0){
		jq('#outerContainer').height(500);
		jq('#imageScroller').height(500);
		jq('#viewer').height(500);
		jq('#viewer').css("overflow-y", "scroll");
	}else{



	if(jq(".wrapper").length > 0){
			
			  //remove js-disabled class
				jq("#viewer").removeClass("js-disabled");
			
			  //create new container for images
				jq("<div>").attr("id", "container").css({ position:"absolute"}).width(jq(".wrapper").length * 225 + jq(".wrapper").length * 12).height(170).appendTo("div#viewer");
			  	
				//add images to container
				jq(".wrapper").each(function() {
					jq(this).appendTo("div#container");
				});
				
				//work out duration of anim based on number of images (1 second for each image)
				var duration = jq(".wrapper").length * 3000;
				
				//store speed for later (distance / time)
				var speed = (parseInt(jq("div#container").width()) + parseInt(jq("div#viewer").width())) / duration;
								
				//set direction
				var direction = "rtl";
				
				//set initial position and class based on direction
				(direction == "rtl") ? jq("div#container").css("left", /*jq("div#viewer").width()*/0).addClass("rtl") : jq("div#container").css("left", 0 /*- jq("div#container").width()*/).addClass("ltr") ;
				
				//animator function
				var animator = function(el, time, dir) {
				 
					//which direction to scroll
					if(dir == "rtl") {
					  
					  //add direction class
						el.removeClass("ltr").addClass("rtl");
					 		
						//animate the el
						el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {
												
							//reset container position
							jq(this).css({ left:jq("div#imageScroller").width(), right:"" });
							
							//restart animation
							animator(jq(this), duration, "rtl");
							
							//hide controls if visible
							(jq("div#controls").length > 0) ? jq("div#controls").slideUp("slow").remove() : null ;			
											
						});
						
					} else {
					
					  //add direction class
						el.removeClass("rtl").addClass("ltr");
					
						//animate the el
						el.animate({ left:jq("div#viewer").width() + "px" }, time, "linear", function() {
												
							//reset container position
							jq(this).css({ left:0 - jq("div#container").width() });
							
							//restart animation
							animator(jq(this), duration, "ltr");
							
							//hide controls if visible
							(jq("div#controls").length > 0) ? jq("div#controls").slideUp("slow").remove() : null ;			
						});
					}
				}
				
				//start anim
				animator(jq("div#container"), duration, direction);
				//jq("div#container").stop(true);
				//pause on mouseover
				jq("a.wrapper").live("mouseover", function() {
				  
					//stop anim
					jq("div#container").stop(true);
					
					//show controls
					/*
					(jq("div#controls").length == 0) ? jq("<div>").attr("id", "controls").appendTo("div#outerContainer").css({ opacity:0.7 }).slideDown("slow") : null ;
					(jq("a#rtl").length == 0) ? jq("<a>").attr({ id:"rtl", href:"#", title:"rtl" }).appendTo("#controls") : null ;
					(jq("a#ltr").length == 0) ? jq("<a>").attr({ id:"ltr", href:"#", title:"ltr" }).appendTo("#controls") : null ;
					*/
					//variable to hold trigger element
					var title = jq(this).attr("title");
					
					//add p if doesn't exist, update it if it does
					(jq("p#title").length == 0) ? jq("<p>").attr("id", "title").text(title).appendTo("div#controls") : jq("p#title").text(title) ;
				});
				
				//restart on mouseout
				jq("a.wrapper").live("mouseout", function(e) {
				  
					//hide controls if not hovering on them
					(e.relatedTarget == null) ? null : (e.relatedTarget.id != "controls") ? jq("div#controls").slideUp("slow").remove() : null ;
					
					//work out total travel distance
					var totalDistance = parseInt(jq("div#container").width()) + parseInt(jq("div#viewer").width());
														
					//work out distance left to travel
					var distanceLeft = (jq("div#container").hasClass("ltr")) ? totalDistance - (parseInt(jq("div#container").css("left")) + parseInt(jq("div#container").width())) : totalDistance - (parseInt(jq("div#viewer").width()) - (parseInt(jq("div#container").css("left")))) ;
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
				
					//restart anim
					animator(jq("div#container"), newDuration, jq("div#container").attr("class"));
//jq("div#container").stop(true);
				});
												
				//handler for ltr button
				jq("#ltr").live("click", function() {
				 					
					//stop anim
					jq("div#container").stop(true);
				
					//swap class names
					jq("div#container").removeClass("rtl").addClass("ltr");
										
					//work out total travel distance
					var totalDistance = parseInt(jq("div#container").width()) + parseInt(jq("div#viewer").width());
					
					//work out remaining distance
					var distanceLeft = totalDistance - (parseInt(jq("div#container").css("left")) + parseInt(jq("div#container").width()));
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
					
					//restart anim
					animator(jq("div#container"), newDuration, "ltr");
					return false;
				});
				
				//handler for rtl button
				jq("#rtl").live("click", function() {
										
					//stop anim
					jq("div#container").stop(true);
					
					//swap class names
					jq("div#container").removeClass("ltr").addClass("rtl");
					
					//work out total travel distance
					var totalDistance = parseInt(jq("div#container").width()) + parseInt(jq("div#viewer").width());

					//work out remaining distance
					var distanceLeft = totalDistance - (parseInt(jq("div#viewer").width()) - (parseInt(jq("div#container").css("left"))));
					
					//new duration is distance left / speed)
					var newDuration = distanceLeft / speed;
				
					//restart anim
					animator(jq("div#container"), newDuration, "rtl");
					return false;
				});
			
	}	
			}	
			});
    
    

    
    
    
    
    
  
  
  
  
  
  
  
var jq = jQuery.noConflict();

jq(document).ready(function(){
	if(jq('.managecontainer').length > 0){
		jq('#scrolling_images').height(300);
		jq('#scrolling_images').css("overflow-y", "scroll");
	}/*else{
	
	if(jq('#scrolling_images').length > 0){
	
	var scroll_index = 0;
	var scroll_width_array = new Array();
	var total_width = 0;
	var counter = 0;
 	jq('#real_width .scrolling_img_container').each(function(i){
		total_width += jq(this).width()+10;
		counter = i+1;

		scroll_width_array[i] = jq(this).width()+10;
	});
//	alert(counter);
	//alert(total_width );
	jq('#real_width').width(total_width + 10);
	
	var pScroll = pScroll;
	
	var time = setInterval(function () {
		var pScroll = scroll_width_array[scroll_index];
		
		if((total_width) <= jq('#scrolling_images')[0].scrollLeft + (pScroll)){
			//alert("dome");
			jq('#scrolling_images').animate({scrollLeft: '-=' + (total_width ) + 'px'}, 1000, 'easeInOutBack');
			scroll_index = 0;
			return;
		}
		
		jq('#scrolling_images').animate({scrollLeft: '+=' + pScroll + 'px'}, 1000, 'easeInOutBack');
		scroll_index++;
		//jq('.scrolling_img_container').html(total_width+" "+(jq('#scrolling_images')[0].scrollLeft + (pScroll*4)));

	
	}, 5000);
	
	
	function scroll_it(){
				var pScroll = pScroll;
		
		
		if((total_width) <= jq('#scrolling_images')[0].scrollLeft + (pScroll)){
			jq('#scrolling_images').animate({scrollLeft: '-=' + (total_width - (pScroll)) + 'px'}, 1000, 'easeInOutBack');
			scroll_index = 0;
		}
		jq('#scrolling_images').animate({scrollLeft: '+=' + pScroll + 'px'}, 1000, 'easeInOutBack');
		scroll_index++;
	}

	jq(".thumbnail").click(function() {
		clearInterval(time);
	});

	jq('#back_arrow').click(function() {
   		var pScroll = pScroll;
    //easeOutQuad
    //easeInOutElastic
    //easeInOutBack
    
    jq('#scrolling_images').animate({scrollLeft: '-=' + pScroll + 'px'}, 1000, 'easeInOutBack');
    if((total_width) >= jq('#scrolling_images')[0].scrollLeft + (pScroll*4)){
    	scroll_index--;
    }
    //alert(jq('#scrolling_images')[0].scrollLeft - (pScroll));
    	//if(jq('#scrolling_images')[0].scrollLeft - (pScroll) <= 0){
    	//	jq('#back_arrow').hide();
    	//}
    	//clearTimeout(t);
    	clearInterval(time);
    	jq('#front_arrow').show();
       return false;
    });
   
   
   
   
   
	jq('#front_arrow').click(function() {
    var pScroll = scroll_width_array[scroll_index];
       	//jq('#back_arrow').show();
    //alert(jq('#scrolling_images')[0].scrollLeft + (pScroll*4) + " ---- " +total_width);
    //if((total_width) <= jq('#scrolling_images')[0].scrollLeft + (pScroll*4)){
    	//alert("en pai allon!!! KANI!!!");
 
    //	jq('#front_arrow').hide();
    //	pScroll = 0;
    //}
    //clearTimeout(t);
    	clearInterval(time);
    jq('#scrolling_images').animate({scrollLeft: '+=' + pScroll + 'px'}, 1000, 'easeInOutBack');
    if((total_width) >= jq('#scrolling_images')[0].scrollLeft + (pScroll*4)){
    	scroll_index++;
    }
  	   return false;
       
    });
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    if(jq('#scrolling_images2').length > 0){
   	
	var total_width2 = 0;
	var counter2 = 0;
 	jq('#real_width2 li').each(function(i){
		total_width2 += jq(this).width()+10;
		counter = i+1;
		var pScroll = jq(this).width()+10;
	});


	jq('#real_width2').width(total_width2 + 10);

	jq('#back_arrow2').click(function() {
    var pScroll = jq('li').width()+10;

    jq('#scrolling_images2').animate({scrollLeft: '-=' + pScroll + 'px'}, 1000, 'easeInOutBack');
    	jq('#front_arrow2').show();
       return false;
    });
   
   
	jq('#front_arrow2').click(function() {
    var pScroll = jq('#real_width2 li').width()+10;
    jq('#scrolling_images2').animate({scrollLeft: '+=' + pScroll + 'px'}, 1000, 'easeInOutBack');
  	   return false;
       
    }); 
    
    
    
    }
    
   
    
    
    }
     */
    
    
    
});
