            $(document).ready(function() {

                //Set Default State of each portfolio piece
                $(".paging").show();
                $(".paging li:first").addClass("active");
		
                //Get size of images, how many there are, then determin the size of the image reel.
                var imageWidth = $(".window").width();
                var imageSum = $(".image_reel img").size();
                var imageReelWidth = imageWidth * imageSum;
	
                //Adjust the image reel to its new size
                $(".image_reel").css({'width' : imageReelWidth});
	
//				$(".paging ul li#m1 a").css({'background-position' : '-225px -2px'});
				$(".paging ul li#m1 a").css({'background-position' : '-225px -57px'});

                //Paging + Slider Function
                rotate = function(){	
                    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
                    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

                    $(".paging li").removeClass('active'); //Remove all active class
                    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
                    		$(".paging ul li#m1 a").removeAttr('style');
                    		$(".paging ul li#m2 a").removeAttr('style');
                    		$(".paging ul li#m3 a").removeAttr('style');
                    		$(".paging ul li#m4 a").removeAttr('style');
                    		$(".paging ul li#m5 a").removeAttr('style');
                    		$(".paging ul li#m6 a").removeAttr('style');
		
                    //Slider Animation
                    $(".image_reel").animate({ 
                        left: -image_reelPosition
                    }, 2500 );
                    	
                    triggerID_check(triggerID);
                    
                    
                    var Prev = triggerID ;
                    var Next = triggerID + 2;
                    if( Next > $(".paging li").size() ){
                        Next = 1;
                    }
                    if( Prev <= 0){
                        Prev = $(".paging li").size();
                    }
                    
                    $('#Prev').attr({ rel:Prev });
                    $('#Next').attr({ rel:Next });
                }; 
	
                //Rotation + Timing Event
                rotateSwitch = function(){		
                    play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
                        $active = $('.paging li.active').next();
                        if ( $active.length === 0) { //If paging reaches the end...
                            $active = $('.paging li:first'); //go back to first
                        }
                        rotate(); //Trigger the paging and slider function
                    }, 8000); //Timer speed in milliseconds (3 seconds)
                };
	
                rotateSwitch(); //Run function on launch

                //On hover
                $(".paging li").hover(function() {	

                    		$(".paging ul li#m1 a").removeAttr('style');
                    		$(".paging ul li#m2 a").removeAttr('style');
                    		$(".paging ul li#m3 a").removeAttr('style');
                    		$(".paging ul li#m4 a").removeAttr('style');
                    		$(".paging ul li#m5 a").removeAttr('style');
                    		$(".paging ul li#m6 a").removeAttr('style');

                    		                	
                    $active = $(this); //Activate the clicked paging
                    
                    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
                    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

                    
                    $(".paging li").removeClass('active'); //Remove all active class
                    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
                    
                    $(".image_reel").css({'left': -image_reelPosition});
                    
                    
                    //Reset Timer
                    clearInterval(play); //Stop the rotation
                    //rotate(); //Trigger rotation immediately
                    //rotateSwitch(); // Resume rotation
                    return false; //Prevent browser jump to link anchor
                }, function() {
					var triggerID = $active.attr("rel") - 1; //Get number of times to slide                	
					triggerID_check(triggerID);
					
                    rotateSwitch(); //Resume rotation
                    
                });
                
                //page Click
                $(".nivo-directionNav a").click(function() {	
                    $active = $(this); //Activate the clicked paging
                    //Reset Timer
                    clearInterval(play); //Stop the rotation
                    rotate(); //Trigger rotation immediately
                    rotateSwitch(); // Resume rotation
                    return false; //Prevent browser jump to link anchor
                });                
                /*
                $(".window").hover(
                    function() {
                        $(".nivo-directionNav").attr({ style:"display:block" });
                    },
                    function() {
                        $(".nivo-directionNav").attr({ style:"display:none" });
                    }
                );
*/
                
            });
            
            function triggerID_check(triggerID){
                    switch ( triggerID+1) {
                    	case 1:
//                    		$(".paging ul li#m1 a").css({'background-position' : '-225px -2px'});
				$(".paging ul li#m1 a").css({'background-position' : '-225px -57px'});
                    		break;
                    	case 2:
                    		$(".paging ul li#m2 a").css({'background-position' : '-225px -2px'});
				//$(".paging ul li#m2 a").css({'background-position' : '-225px -57px'});
                    		break;
                    	case 3:
                    		$(".paging ul li#m3 a").css({'background-position' : '-225px -111px'});
                    		break;
                    	case 4:
                    		$(".paging ul li#m4 a").css({'background-position' : '-225px -165px'});
                    		break;
                    	case 5:
                    		$(".paging ul li#m5 a").css({'background-position' : '-225px -219px'});
                    		break;
                    	case 6:
                    		$(".paging ul li#m6 a").css({'background-position' : '-225px -273px'});
                    		break;
                    	default:
//   				$(".paging ul li#m1 a").css({'background-position' : '-225px -2px'});
				$(".paging ul li#m1 a").css({'background-position' : '-225px -57px'});
                    }            	
            }
