function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function isBrowserOld(){
	var browserVer = -1;
	if ( $.browser.msie ) {
	  browserVer = parseInt($.browser.version, 10);
	}	
	if (browserVer < 0 || browserVer >= 7) //allow ie7, so basically no need in this method
		return false;
	else{
		$('#browsererror').show();
		return true;
	}
}

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	$('#content').fadeIn(2000);
	$('#content').css('display','inline-block');
	var browserVer = -1;
	if ( $.browser.msie ) {
	  browserVer = parseInt($.browser.version, 10);
	}
	var m = 0;
	if (browserVer < 0 || browserVer > 7){
		m = 3;
	}
	if (browserVer > 0 && browserVer < 7){
		//alert('Your browser is not supported, please try open this page in another browser!!!');
		$('#wrapper').hide();
		$('body').html('<p style="padding:40px">Your browser is not supported, please try open this page in another browser!<br/>For questions, please email to: <a href="mailto:it@cnwglobal.com?subject=Incompatible browser">it@cnwglobal.com</a></p>');
	}
	var margin = $('body').outerHeight(true) - $('body').height();
	$('.manicon').css('bottom',-(margin + m) + 'px');
	
	$('.manicon').fadeIn(3000);
	//$('#rightupper').addClass('round').animate(2000);
	$('.back').addClass('round').animate(2000);
	$('.back2').addClass('circle').animate(2000);
	
	$('#searchdiv').click(function(){
		var value = $('#track').val();
		if (value != null && value.trim().length > 0){
			value = value.trim().replace(/\n/g,'+');
			//window.open('http://213.8.146.125/cnw/?awbnumber=' + value);
			//window.location = "/tracking.html?awbnumber=" + value;
			$('#trackbutton').attr('href','tracking.html?awbnumber=' + value);
		}
		else{
			$('#trackbutton').attr('href','#');
		}
	});

});

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}


function parseXML(id){
	
	//parse xml
	  //find every Tutorial and print the author
	$.ajax({
		url:'content/content.xml',
		dataType: 'xml',
		success: function(data){
			var xml = $(data);
			  $(xml).find(id).each(function()
			  {
				$("#" + id).html($(this).text());
			  });
		}
	});
}
function insertMenu(){
	
	//parse xml
	  //find every Tutorial and print the author
	$.ajax({
		url:'menu.html',
		type:'GET',
		dataType: "html",
		success: function(data){
			$('#menu').html(data);
		}
	});
}
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
