/*
 * Project: Scorpio Mining Corporation
 * Author: Rudy Affandi
 * Created: 12/29/2010
 * File name: functions.js
 */

// jQuery initialization and CSS settings
$(function(){
	$( '.header_top_nav' ).addClass('ui-corner-bl ui-corner-br');

	// Add text shadow to Legal disclaimer footer
	if ($.browser.msie) {
	 	$(".legal").textShadow();
		$(".front_left_col h2").textShadow();
		$(".front_right_col h2").textShadow();
	}

	// jQuery form validator (for email unsubscribe)
	$("#form1").validate();

	// add dynamically generated drop shadow and redraw after every window resize	
	$( '.gallery_grid ul li a img' ).dropShadow({left: 1, top: 1, opacity: 0.1, color: '#333'});
	$(document).ready(function(){
		$(window).bind("resize", resizeWindow);
		function resizeWindow() {
			$( '.gallery_grid ul li a img' ).redrawShadow({left: 1, top: 1, opacity: 0.1, color: '#333'});
		}
	});

	// Main navigation drop down settings
	$(document).ready(function () {   
		$('.main_nav li').hover(function () {  
			//show its submenu  
			$('ul', this).slideDown(120);
		},   
		function () {  
			//hide its submenu  
			$('ul', this).slideUp(120);
		});  
	});	

	// Activate "class='active'" on current URL
	var path = location.pathname.substring(1);
   if ( path )
     $('.side_nav ul li a[href$="' + path + '"]').attr('class', 'active');
     $('ul.main_nav li a[href$="' + path + '"]').attr('class', 'active');

	// For URL with parameters
	var path2 = location.search.substring(1);
   if ( path2 )
     $('.side_nav ul li a[href$="' + path2 + '"]').attr('class', 'active');
     $('ul.main_nav li a[href$="' + path2 + '"]').attr('class', 'active');


	// Front page image crossfades
	rotator();
});

function rotator() {
	$('.front_header_banner div').css('opacity', 0)
   .eq(0).css('opacity', 1).addClass('active');
   setInterval('rotateIt()', 5000);
}

function rotateIt() {
    // Get the first image
    var currentImg = $('.front_header_banner div.active') ? $('.front_header_banner div.active') : $('.front_header_banner div:first');

	// Get next image, when it reaches the end, rotate it back to the first image
    var nextImg = (currentImg.next().length) ? (currentImg.next().hasClass('active')) ? $('.front_header_banner div:first') : currentImg.next() : $('.front_header_banner div:first');	
	
	// Set the fade in effect for the next image, the active class has higher z-index
	nextImg.css('opacity', 0)
	       .addClass('active')
	       .animate({opacity: 1}, 1500);

	// Hide the current image
	currentImg.animate({opacity: 0}, 1500)
	          .removeClass('active');
                  
}

