$(window).load(function() {
	$('#mainslider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:1000,
		pauseTime:4500,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next and Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		keyboardNav:true, //Use left and right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
	
	var newsitems;
	var curritem=0;
	var iPause=0;
	
	$(document).ready(function(){
	    var tickerSelector = "#sideticker li";
	    newsitems = $(tickerSelector).hide().hover(
	        function(){
	            $(this).addClass("hovered");
	            iPause=1;
	        },
	        function(){
	            $(this).removeClass("hovered");
	            iPause=0;
	        }
	    ).filter(":eq(0)").show().add(tickerSelector).size();
	    setInterval(ticknews,4000); //time in milliseconds
	
	
		//MODAL
		//select all the a tag with name equal to modal  
		    $('a[name=modal]').click(function(e) {  
		        //Cancel the link behavior  
		        e.preventDefault();  
		        //Get the A tag  
		        var id = $(this).attr('href');  

		        //Get the screen height and width  
		        var maskHeight = $(document).height();  
		        var maskWidth = $(window).width();  

		        //Set height and width to mask to fill up the whole screen  
		        $('#mask').css({'width':maskWidth,'height':maskHeight});  

		        //transition effect       
		        $('#mask').fadeIn(1000);      
		        $('#mask').fadeTo("slow",0.8);    

		        //Get the window height and width  
		        var winH = $(window).height();  
		        var winW = $(window).width();  

		        //Set the popup window to center  
		        $(id).css('top',  winH/2-$(id).height()/2);  
		        $(id).css('left', winW/2-$(id).width()/2);  

		        //transition effect  
		        $(id).fadeIn(2000);   

		    });  

		    //if close button is clicked  
		    $('.window .close').click(function (e) {  
		        //Cancel the link behavior  
		        e.preventDefault();  
		        $('#mask, .window').hide();  
		    });       

		    //if mask is clicked  
		    $('#mask').click(function () {  
		        $(this).hide();  
		        $('.window').hide();  
		    });
		
		
		
			//Other Ticker

			// Expand Panel
			$("#open").click(function(){
				$("div#panel").slideDown("slow");
			});	

			// Collapse Panel
			$("#close").click(function(){
				$("div#panel").slideUp("slow");
			});		

			// Switch buttons from "Log In | Register" to "Close Panel" on click
			$("#toggle a").click(function () {
				$("#toggle a").toggle();
			});
	});
	
	$("#dropmenu ul").css({display: "none"}); // Opera Fix 
	$("#dropmenu li").hover(
		function(){ 
			jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).show(268); 
		},
		function(){ 
			jQuery(this).find('ul:first').css({visibility: "hidden"}); 
		}
	);
	
	function ticknews() {
		  if (iPause==0){
			$("#sideticker li:eq("+curritem+")").css('position', 'absolute');
		    $("#sideticker li:eq("+curritem+")").fadeOut("slow",function(){$(this).hide();});
		    curritem = ++curritem%newsitems;

			$("#sideticker li:eq("+curritem+")").css('position', 'absolute');
		    $("#sideticker li:eq("+curritem+")").fadeIn("slow");
		    }
		}
	
});
