// JavaScript Document
$(document).ready(function() {
	
    var scroll = false;
	var scrollSpeed = 175;
	
	// View Older cartoons
    var ScrollLeft = function() {
		var position = $('#TmbStrip').position();

		if(scroll){
			
			if(position.left < -80){
			 $('#TmbStrip').animate({
				left: "+=88px"
			  }, scrollSpeed, 'linear', function() {
				// Animation complete.
				if(scrollSpeed > 20){
				scrollSpeed -= 3;
				}
				ScrollLeft();
			  });
			}
		
		}//! if scroll true
    }
	
	$('#ArrowOld').mousedown(function() {
		scroll = true;
		ScrollLeft();
	}).mouseup(function() {
		scrollSpeed = 175;
		scroll = false;
	});
	
    var ScrollRight = function() {
		var position = $('#TmbStrip').position();

		if(scroll){

/*			if(position.left > (($('#TmbStrip').width()-616)*(-1))){				
			 $('#TmbStrip').animate({
				left: "-=88px"
			  }, 200,'linear', function() {
				// Animation complete.
				ScrollRight();
			  });
			}*/
			
			if(position.left > (($('#TmbStrip').width()-616)*(-1))){
			 $('#TmbStrip').animate({
				left: "-=88px"
			  }, scrollSpeed, 'linear', function() {
				// Animation complete.
				if(scrollSpeed > 20){
				scrollSpeed -= 3;
				}
				ScrollRight();
			  });
			}
		
		}//! if scroll true
    }
	
	$('#ArrowNew').mousedown(function() {
		scroll = true;
		ScrollRight();
	}).mouseup(function() {
		scroll = false;
	});
	
	
	// safety catch all - prevents continuouse scroll if mousup off button
	$(document).mouseup(function() {
		scroll = false						 
	});
	
	
	$('.VeiwLarge').click( function(){
		var cartoonUrl = $(this).attr('src');
		//alert(cartoonUrl.replace("Thumbnails", "Cartoons"));
		$('#CartoonShell').html('<img src="'+cartoonUrl.replace("Thumbnails", "Cartoons")+'" />');			
	});
	
	
	$(document)[0].oncontextmenu = function(e) {
		//alert("Not Happening!");
//Rotate
/*$('#Window').css('-moz-transform', 'rotate(120deg)');
$('#Window').css('-webkit-transform', 'rotate(120deg)');*/
$('#Window').animate({'-webkit-transform':'rotate(120deg)', '-moz-transform':'rotate(120deg)'}, 500);
/*		
// Animate window minimize
$('#Window').animate({
	height: "2px"
	}, 500, function() {
		// Animation complete.
}).animate({
	width: "2px"
	}, 500, function() {
			// Animation complete.
							
});	



// Stone Chip
$('#Shell').before('<div style="position:absolute; width:258px; height:214px; top:'+(e.pageY - 100)+'px; left:'+(e.pageX - 100)+'px; z-index:999; background-image:url(\'images/stonechip.png\');"></div>');
*/



		//var StoneChip = $(document).add('<div>');
		//StoneChip.attr('src', 'images/stonechip.png').css('position', 'absolute').css('top', '200px').css('left','200px');
		
		return false;
	}; 

});
