// JavaScript Document

function say(word) {
	alert (word);
}

function iPadBanner(webPage, imageName, imageNum, imageLink, linkTarget) {
	
	if ((navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('iPhone') != -1)) {
		
		
		//remove desktop Flash
		$("div#desktopFlash").remove();
	
		//define image path
		switch (webPage) {
			case "home":
			webPage = "/ContentManagement/Images/Home/";
			break;
			
			case "Image search":
			webPage = "/contentmanagement/images/Search/";
			break;
			
			case "Collections":
			webPage = "/contentmanagement/Images/Collections/";
			break;
			
			case "Royalty-free":
			webPage = "/contentmanagement/images/Royaltyfree/";
			break;
			
			case "Special offers":
			webPage = "/contentmanagement/images/SpecialOffers/";
			break;
			
			default:
			alert("The web page name is not correct");
			break;
		}
				
		// if one static image:
		if (imageNum == 1)
		imageRand = "";
		
		else {
			//get a random image
			var imageRand = Math.ceil(Math.random()*imageNum);
			if (imageRand < 10)
			imageRand = "0" + imageRand;
		}
		
		
		// append the banner
		$('div#iPadBanner').append('<a href="'+imageLink+'" target="'+linkTarget+'"><img class="slides" src="'+webPage+imageName+imageRand+'.jpg" border="0" alt="iPad banner" /></a>');

						
	}
	
	//else remove iPad banner
	
}

function iPadMainBanner(webPage, imageName, imageWidth, imageHeight, imageNum, imageLink, linkTarget) {
	
	if ((navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('iPhone') != -1)) {
		
		//remove desktop Flash
		$("#desktopFlash").remove();
	
		//define image path
		switch (webPage) {
			case "home":
			webPage = "/ContentManagement/Images/Home/";
			break;
			
			case "Image search":
			webPage = "/contentmanagement/images/Search/";
			break;
			
			case "Collections":
			webPage = "/contentmanagement/Images/Collections/";
			break;
			
			case "Royalty-free":
			webPage = "/contentmanagement/images/Royaltyfree/";
			break;
			
			case "Special offers":
			webPage = "/contentmanagement/images/SpecialOffers/";
			break;
			
			default:
			alert("The web page name is not correct");
			break;
		}
				
		// if one static image:
		if (imageNum == 1)
		imageRand = "";
		
		else {
			//get a random image
			var imageRand = Math.ceil(Math.random()*imageNum);
			if (imageRand < 10)
			imageRand = "0" + imageRand;
		}
		
		var newImage = webPage+imageName+imageRand;
		// append the banner
		$('#iPadBanner').css({'width':imageWidth+'px', 'height':imageHeight+'px'});
		$('#iPadBanner').append('<a href="'+imageLink+'" target="'+linkTarget+'"><img class="slides" src="'+webPage+imageName+imageRand+'.jpg" width="'+imageWidth+'" height="'+imageHeight+'" border="0" alt="iPad banner" /></a>');
		
		
		
		// rotate iamges
		setInterval(function() {
			var preNum = imageRand;
			
			imageRand = Math.ceil(Math.random()*imageNum);
			
			if (imageRand == preNum)
			imageRand++;
			
			if (imageRand > imageNum)
			imageRand = 1;
			
			if (imageRand < 10)
			imageRand = "0" + imageRand;
			
			newImage = webPage+imageName+imageRand;
					
			$('img.slides').attr("src", newImage+".jpg");
			/*
			$('img.slides').hide().load(function() {
				$(this).fadeIn(1000);
			});
			*/

		}, 5000);
		
	}
	
	else $('#iPadBanner').remove();

}


