$(document).ready(function() {
        
        if(jQuery.browser.msie && (jQuery.browser.version >= 6 )){
	        $('#content').append('<div id="myScreen" class="modal-overlay"></div>');
	        var screenPosition = $('#content').offset();
	        var screenLeft = 0 - screenPosition.left;
	        var screenTop = 0 - screenPosition.top;
	        var screenWidth = $('body').outerWidth();
	        var screenHeight = $('body').outerHeight();
	        $('#myScreen').css({
	            'left':screenLeft,
	            'top':screenTop,
	            'width':screenWidth,
	            'height':screenHeight
	        });
	    } else {
	        $('body').append('<div id="myScreen" class="modal-overlay"></div>');
	    }
          
        var modal = "";  
        modal += '<div id="myModal" class="modal-window">';      
        modal += '<div class="close-window"><a href="#"><img src="images/btn_close.gif"/></a></div>';      
        modal += '<div class="moreslideshows"><a href="#"><img src="images/btn_moreslideshows.gif"/></a></div>';      
        modal += '<div class="slideshowmenu redtrans">&nbsp;</div>';      
        modal += '<div id="moresshighlight" class="moreslideshows"><a href="#"><img src="images/btn_moreslideshows_red.gif"/></a></div>';      
        modal += '<div id="ssmenu" class="slideshowmenu">&nbsp;</div>';      
        modal += '<div class="window-text"></div>';      
        modal += '<div id="slideshow"><div class="loader"><img src="images/ajax-loader.gif"/></div></div>';      
        modal += '</div>';      
  
        $('#content').append(modal);
        
//      var moveMenu = '<ul>' + $('#slideshowchoices ul').html() + '</ul>';
//		This function used to copy the list of slideshows from the blue bar on the homepage. So that the slideshow
//		can work on pages other than the homeapge, that code is now included here in a string instead.

		var moveMenu = '<ul style="z-index:200;"><li><a href="#" id="irresistible"><span class="title">Irresistible Trinity</span> Green lawns, gurgling fountains, and gorgeous red brick. <span class="fauxlink"><u>Play</u> &raquo;</span></a></li><li><a href="#" id="inexhaustible"><span class="title">Inexhaustible Trinity</span> Get busy: 130 student organizations await.  <span class="fauxlink"><u>Play</u> &raquo;</span></a></li><li><a href="#" id="customizable"><span class="title">Customizable Trinity</span> You’re free to grow in any direction. <span class="fauxlink"><u>Play</u> &raquo;</span></a></li></ul>';
        $('#myModal .slideshowmenu').append(moveMenu);
        
        $('#myModal .close-window').click(function() {
        	$('#myModal').hide();
        	$('#myScreen').hide();
        });
        
        $('#myModal .close-window').click(function() {
        	$('#myModal').hide();
        	$('myScreen').hide();
        });
        
        
        $('.moreslideshows a').click(function() {
        	$('#myModal .slideshowmenu').toggle()
        	$('#myModal #moresshighlight').toggle()
        });
        
        
        $('#ssmenu a').click(function() {
            $('#slideshow #pix').cycle(0); 
        	$('#myModal .slideshowmenu').hide();
        	$('#myModal #moresshighlight').hide();
       		var whichss = $(this).attr('id');
       		goSlideshow('slideshow_' + whichss + '.html');
        });
        
        $('a#irresistible').click(function() {
        	$('#slideshow #pix').cycle(0); 
        	goSlideshow('slideshow_krtu1.html');
        });

        $('a#inexhaustible').click(function() {
        	$('#slideshow #pix').cycle(0); 
        	goSlideshow('slideshow_krtu2.html');
        });

        $('a#customizable').click(function() {
         	$('#slideshow #pix').cycle(0); 
        	goSlideshow('slideshow_krtu3.html');
        });

		function goSlideshow(sourcePage) {
		
			var textSource = sourcePage + ' #text';
			var slideSource = sourcePage + ' #pix';
			
        	$('.modal-overlay').fadeIn().css('filter', 'alpha(opacity=79)');
        	$('#myModal:hidden').fadeIn(500);
	        $('#slideshow').load(slideSource, function() {
	        	$('#myModal #nav').remove();
				$('#myModal').append('<div id="nav"><a href="#" id="prev" style="padding-right:10px;"><img src="images/btn_previous.gif" border="0"/></a><span id="pager"></span><a href="#" id="next" style="padding-left:10px;"><img src="images/btn_next.gif" border="0"/></a></div>');
	        	$('#myModal .window-text').load(textSource);
	   		    $('#slideshow #pix').cycle(0).cycle({ 
	    			fx:      'fade', 
	    			speed:     750, 
	    			timeout:   5000, 
	    			next:   '#next', 
	    			prev:   '#prev',
					pause:	      1,
					after: onAfter,
					startingSlide: 0,
					pager:  '#pager'
				});
			});
			
			function onAfter() { 
    			$('#myModal .window-text p').html(''); 
    			$('#myModal .window-text p').html(this.alt); 
			}
			
			$('#myModal .slideshowmenu').css('z-index','10');

			
		}
		
	    $('#homepageslideshow ').cycle({ 
			fx:      'fade', 
			speed:     750, 
			timeout:   5000
		});
		$('#slideshowchoices').css('z-index','10');
		
		
});
