//
// DOM LOAD FUNCTIONS


// add class to show js enabled (all javascript enabled css styles can be prepended with html.js)
$('html').addClass('js preloading');


$(function(){


	//
	//	GLOBAL
	//	================================================================================================================================================
	// open rel="external" links in new window (instead of target="_blank")
	$("a[rel='external']:not(.downGuideHolder)").addClass("external").click( function() { window.open( $(this).attr('href') ); return false; } );
	// add hover class to buttons(and other elements) for easier css styling
	$("button, .button, #letterNav .group:not(.cur), #closeCut, .hovers .size")
		.live('mouseenter', function() {
			$(this).addClass('hover');
		})
		.live('mouseleave', function() {
				$(this).removeClass('hover');
		});
	// add focus class to text inputs and textareas for easier css styling
	$("input:text, input:password, textarea")
		.live('focus', function() {
			$(this).addClass('focus');
		})
		.live('blur', function() {
			$(this).removeClass('focus');
		});


	//
	//	PRETTYLOADER
	//	================================================================================================================================================
	$.prettyLoader();


	//
	//	CHANGE #STAGE background COLOUR FOR WIDE SCREENS + FADE IN #STAGE
	//	================================================================================================================================================
	function showStage() {
		$("#stage").animate({opacity: 1}, 1000, function() {
			$("#stage").css('background-color','#ede8dd'); // set background-color
			showForevermarkSettingAnimation();
		});
	}
	function ieShowStage() {
		$("#stage").css("visibility","visible").css('background-color','#ede8dd'); // set background-color
		initCufon();
		showForevermarkSettingAnimation();
	}
	// non IE fading
	if (!$.browser.msie) {
		$("#stage").css("opacity","0").css("visibility","visible"); // visibility:hidden; already set in css
		var imageTot = $("#stage img").length; // total images in #stage
		var cImage = 1; // image iterator
		if (imageTot > 0 ) {
			$("#stage img")
				.one("load", function () {
					cImage++;
					if (cImage == imageTot || imageTot == 1) {
						showStage();
					}
				})
				.each(function(){
					// fix for cached images
					if(this.complete) {
						$(this).trigger("load");
					}
				});
		} else {
			// fix for 0 images
			showStage();
		}
	// IE fading
	} else {
		$(window).load(function(){
			ieShowStage();
		});
	}


	//
	//	SCROLLABLE DIVS (jScrollPane)
	//	================================================================================================================================================
	function initScroll(selector) {
		$(selector).jScrollPane( {showArrows:true, scrollbarWidth:11} ); // initiate jScrollPane
		$('.jScrollPaneDrag').css( { width:'1px', left:'5px' } ); // default to slimline scrubber
		 // animate to slimline scrubber on mouseleave
		function shrinkDrag() {
			$('.jScrollPaneContainer').bind('mouseleave', function() {
				$('.jScrollPaneDrag',this).animate( { width: 1, left: 5 }, { queue:false, duration:250 } );
			});
		}
		shrinkDrag();
		// attach mouseenter to scroll container
		$('.jScrollPaneContainer').bind('mouseenter', function() {
			// thicken scrubber
			$('.jScrollPaneDrag',this).animate( { width: 7, left: 2 }, { queue:false, duration:250 } );
			// attach mousedown on scrubber
			$('.jScrollPaneDrag',this).mousedown(function() {
				$('.jScrollPaneContainer').unbind("mouseleave"); // unbind mouseleave event
				// bind mouseup to body
				$('body').mouseup(function(e) {
					// animate to slimline if IS NOT ".jScrollPaneContainer" element and NOT child of ".jScrollPaneContainer"
					if ( !$(e.target).hasClass('jScrollPaneContainer') && $(e.target).parents('.jScrollPaneContainer').length === 0  ) {
						$('.jScrollPaneDrag').animate( { width: 1, left: 5 }, { queue:false, duration:250 } );
					}
					shrinkDrag();
				});
			});
		});
	}
	initScroll('.scrollable');


	//
	//	CAPTURE DEFAULT CUT IMAGE
	//	================================================================================================================================================
	$('#contentWrapper .col-m img').data('defaultImage', $('#contentWrapper .col-m img').attr('src'));


	//
	//	FAUX SELECTS
	//	================================================================================================================================================
	$('.fauxSelect')
		.bind('mouseenter', function() {
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {$('.fauxSelect').not(this).addClass('zFix');} // fix IE<8 z-index issues
			$(this).addClass('open');
		})
		.bind('mouseleave', function() {
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {$('.fauxSelect').removeClass('zFix');} // fix IE<8 z-index issues
			$(this).removeClass('open');
		})
		.bind('click', function(event) {
			event.preventDefault();
			var $elem = $(event.target).closest("a");
			if ($elem.length) {
				$elem
					.siblings('a').removeClass('selected') // unselect sibling anchors
					.end()
					.addClass('selected') // select clicked anchor
					.prevAll('span').addClass('hidden') // hide span (faux label)
					.end();
				$(this).removeClass('open'); // close .fauxSelect
				 // call page actions for anchor here
				$('#tempHolder p').html('Current Link: '+$elem.html());
				// actions on cut page
				if ( $(this).attr('id') == 'cutSelect' ) {
					$("#cutDescHolder .cutDesc").removeClass('cutDescShow').addClass('cutDescHide');
					$("#diamondHolder").hide(); // hide flash
					if ( $("#contentWrapper .col-m > img").length > 0 ) { // if there's already an image, then switch out the src
						$("#contentWrapper .col-m > img").attr('src', $($elem.attr('href')+' img').attr('src') ); // switch image
					} else { // add image
						$("#diamondHolder").after('<img src="' + $($elem.attr('href')+' img').attr('src') + '" width="320" height=320 />');
					}
					// Tracking SiteCatalyst - start
					try { sc_trackLink($elem.text(),'Faux')} catch (e) {}
					// Tracking SiteCatalyst - end
					$("#cutDescHolder").addClass('visible');
					$($elem.attr('href')).removeClass('cutDescHide').addClass('cutDescShow');
					$('#closeCut').bind('click', function(event) {
						$("#cutDescHolder").removeClass('visible');
						$("#cutDescHolder .cutDesc").removeClass('cutDescShow').addClass('cutDescHide');
						$("#diamondHolder").show(); // show flash
						$("#contentWrapper .col-m > img").remove(); // remove image
						$("#cutSelect").find('a, span').removeClass('hidden selected'); // reset faux select
					});
				}
			}
		});


	//
	//	NAVIGATION
	//	================================================================================================================================================
	// hover image switching
	var navHoverImagesArray = [];
	$(".nav li:not(.selected) a")
		.hover(function(e) {
			$('img',this).attr('src',$('img',this).data('hoversrc'));
		}, function(e) {
			$('img',this).attr('src',$('img',this).data('src'));
		})
	// preload navigation hover images
		.each(function () {
			$('img',this).attr('alt','').attr('title',''); // hide tooltips for neatness
			$(this).attr('title',''); // hide tooltips for neatness
			var src = $('img',this).attr('src');
			var hoversrc = $('img',this).attr('hoversrc');
			$('img',this).data('src', src);
			$('img',this).data('hoversrc', hoversrc);
			navHoverImagesArray.push(hoversrc);
		});
		jQuery.preLoadImages(navHoverImagesArray);
	// footer single item
	if ( $("#nav-sub > ul > li").length == 1 ) {
		$("#nav-sub > ul > li").addClass('single').append('<span class="bookend2"></span><span class="line2"></span>');
	}


	//
	//	FIX IE6 MIN-WIDTH ON #WRAPPER <DIV>
	//	================================================================================================================================================
	// function to resize the container
	function addMinWidths() {
		var minW = parseInt($('#wrapper').css('min-width'), 10); // grab wrapper min-width from css
		var currentW = parseInt($("#wrapper").outerWidth(true), 10); // grab actual width from page
		if (currentW <= minW) {
			new_width = minW;
		} else {
			new_width = 'auto';
		}
		$('#wrapper').css({width: new_width});
	}
	if ($.browser.msie && $.browser.version <= 6 ) {
		addMinWidths(); // call on page load
	}


	//
	//	FIX IE7 AND BELOW FIXED WIDTH OF NAVIGATION
	//	================================================================================================================================================
	if ($.browser.msie && $.browser.version <= 7 ) {
		var liW = 0;
		var mes = '';
		$("#nav-main .nav-secondary > li").each(function(index) {
			liW += parseInt($(this).outerWidth(true), 10);
			mes = mes + '+' + parseInt($(this).outerWidth(true), 10);
		});
		$("#nav-main .nav-secondary").css('width',liW+'px');
		$("#nav-main").addClass('adjusted');
		$('html').removeClass('preloading');
	}


	//
	//	POP UP BOXES (use .pop for default)
	//	================================================================================================================================================
	// http://www.quirksmode.org/js/popup.html
	function popitup(url, width, height) {
		newwindow=window.open(url,'name','height=' + height + ',width=' + width + ',location=0,menubar=0,resizable=0,scrollbars=0,statusbar=false,dependent,alwaysraised,status=false,titlebar=no,toolbar=0,hotkeys=0,');
		if (window.focus) {newwindow.focus();}
		return false;
	}
	$(".pop:not(#send, #exclusive)").live('click', function(e) {
		e.preventDefault();
		if ( !$(this).hasClass('disabled') ) { // check that this is NOT disabled
			$(".pop.disabled").removeClass('disabled'); // UN-disable all other popup links
			$(this).addClass('disabled'); // disable this popup link (to prevent double-clicking)
			$(".popUpBox").remove(); // remove any current popups
			// grab variables
			var href = $(this).attr('href');
			var title = $(this).attr('title'); /* used for Glossary page */
			var id = $(this).attr('id');
			var heading = $(this).text();
			var copy = $(this).siblings('p').html();
			var img = $(this).siblings('img').attr('src');
			// Tracking SiteCatalyst - start
			try { 
				if ((title!="") && (title.match(/[a-z|A-Z]/))) sc_trackPage(title.toLowerCase());
				else if ((heading!="") && (heading.match(/[a-z|A-Z]/))) sc_trackPage(heading.toLowerCase());
				else if ((id!="") && (id.match(/[a-z|A-Z]/))) sc_trackPage(id.toLowerCase());
				else sc_trackPage(href.substr(0,href.length-1).toLowerCase());
			} catch (error) {}
			// Tracking SiteCatalyst - end
			img += '';  // This converts img to string if not set
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {$("select").css('visibility','hidden');} // fix IE6 <select> issues
			$('<div class="popUpBox ajaxPop" id="pop-'+id+'" style="display:none;"><div class="popUpContent"></div></div>').appendTo('#stage'); // add .popUpBox and .popUpContent to page
			// GLOSSARY SPECIFIC POPUP
			if (href == "#glossary" || ( $('body').hasClass('glossary') && id != 'send') ) {
				$('.popUpBox').attr('id','pop-full-story');
				var imgStr = '';
				if (img.length > 20) {
					imgStr = '<img src="'+img+'" />';
				}
				$('<div class="col col-l w350"><h2 class="popUpHeader noCufon">'+title+'</h2><div id="cutStory" class="scrollable blurb"><p>'+copy+'</p></div></div><div class="col col-r">'+imgStr+'</div>').appendTo('#stage #pop-full-story .popUpContent');
				$('<a class="popUpClose" href="#">Close</a>').appendTo('.popUpContent'); // add close button
				$('.popUpContent > *').css('visibility','hidden'); // hide contents of popUpContent
				// show popup contents
				$(".popUpBox").fadeIn(600, function() {
					initScroll('.popUpContent .scrollable'); // RE-initiate jScrollPane for popUpContent
					$('.popUpContent > *').hide().css('visibility','visible').fadeIn(); // show contents of popUpContent
					if ($.browser.msie && $.browser.version.substr(0,1)<8) {$("select",this).css('visibility','visible');} // fix IE6 <select> issues
					$(this).addClass('visible');
				});
			} else {
				// STANDARD POPUP
				// load page into container
				$('.popUpContent').load(href+' .popUpContent > *', function(response, status, xhr) {
					$('<a class="popUpClose" href="#">Close</a>').appendTo('.popUpContent'); // add close button
					$('.popUpContent > *').css('visibility','hidden'); // hide contents of popUpContent
					// show popup contents
					$(".popUpBox").fadeIn(600, function() {
						initScroll('.popUpContent .scrollable'); // RE-initiate jScrollPane for popUpContent
						 // RE-initiate 360 zooms for popUpContent
						if ( id == 'ring' || id == 'pendant' || id == 'earring' ) {
							$(".popUpContent #ring .spin").threesixty({images:$("#ring").data('imagesZ')});
							$(".popUpContent #pendant .spin").threesixty({images:$("#pendant").data('imagesZ')});
							$(".popUpContent #earring .spin").threesixty({images:$("#earring").data('imagesZ')});
						}
						$('.popUpContent > *').hide().css('visibility','visible').fadeIn(); // show contents of popUpContent
						if ($.browser.msie && $.browser.version.substr(0,1)<8) {$("select",this).css('visibility','visible');} // fix IE6 <select> issues
						$(this).addClass('visible').css('display', 'block');
					});
				});
			}
		}
	});
	$('.popUpClose').live('click', function(e) {
		e.preventDefault();
		$(".popUpBox").fadeOut(400,function() {
			$(this).removeClass('visible');
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {$("select").css('visibility','visible');} // fix IE6 <select> issues
			$(".popUpBox").remove(); // remove popups
			$(".pop.disabled").removeClass('disabled'); // UN-disable all popup links
		});
	});
	$("#send.pop").live('click', function(e) {
		popitup($(this).attr('href'), 970, 428);
		return false;
	});
	$("#exclusive.pop").live('click', function(e) {
		popitup($(this).attr('href'), 1100, 428);
		return false;
	});	


	//
	//	ZOOM IMAGE
	//	================================================================================================================================================
	$('#contentWrapper div.zoom')
		.bind('mouseenter mouseover', function(e) {
			var zoomFactor = 5;
			var holder = $('#zoomHolder',this);
			var offset = $(this).offset();
			var xOffset = holder.outerWidth(true)/2;
			var yOffset = holder.outerHeight(true)/2;
			$(this).bind('mousemove', function(e) {
				var x = e.pageX - offset.left;
				var y = e.pageY - offset.top;
				if ( x<14 || y<14 || x>306 || y>306) { // hide if out of bounds - where did I get these numbers from?
					holder.removeClass('show');
				} else {
					holder.addClass('show');
					var xHolder = parseInt( ( x - xOffset), 10 );
					var yHolder = parseInt( ( y - yOffset), 10 );
					holder.css({ 'top' : yHolder, 'left' : xHolder });
					var xZoom = parseInt( -x*zoomFactor+xOffset, 10);
					var yZoom = parseInt(-y*zoomFactor+yOffset, 10);
					$('img', holder).css({ 'top' : yZoom, 'left' : xZoom });
				}
			});
		});


	//
	//	COLOUR/CLARITY SELECT
	//	================================================================================================================================================
	$('#letterNav .group')
		.live('click', function(e) {
			$(this)
				.addClass('cur')
				.siblings().removeClass('cur').removeAttr('style');
			var newImage = $('img',this).attr('src');
			var newHeading = $('img',this).attr('alt');
			var newCopy = $('i',this).text();
			// Tracking SiteCatalyst - start
			try { 
				if ((newHeading!="null") && (newHeading!="")) sc_trackLink(newHeading,'Detail');
				else sc_trackLink($('span',$(this)).text(),'Detail');
			} catch(err){}
			// Tracking SiteCatalyst - end
			if ( $(e.target).closest('#letterNav').hasClass('colourLetters') ) {
				$('#contentWrapper h2').html(newHeading);
				$('#contentWrapper .col-m img').attr('src',newImage);
			} else if ( $(e.target).closest('#letterNav').hasClass('clarityLetters') ) {
				$('.popUpContent .scrollable p').text(newCopy);
				$('.popUpContent .col-r img').attr('src',newImage);
			}
			initScroll('.popUpContent .scrollable');
		});
	$("#letterNav .group:not(.cur)")
		.live('mouseenter', function() {
			$(this).siblings().removeAttr('style'); // reset styles on other groups
			$(this).animate( { backgroundColor: '#eeeeee' }, 250);
		})
		.live('mouseleave', function() {
			$(this).siblings().removeAttr('style'); // reset styles on other groups
			$(this).animate( { backgroundColor: '#ffffff' }, 250);
		});


	//
	//	GLOSSARY UL COLUMN SPLITTER (IE + OPERA)
	//	================================================================================================================================================
	$("#columnWrapper > li").each(function(i) {
		if ($(this).children('p').length < 1) {
			$(this).remove(); // remove <li>s without content
		}
	});
	if ( $('#columnWrapper').length > 0 && ($.browser.msie || $.browser.opera) ) {
		var $wrapper = $('#columnWrapper'); // define <ul>
		var $lis = $('> li', $wrapper); // define <li>s
		var cols = 4; // default to 4 columns
		if ($('body').hasClass('ja-jp') || $('body').hasClass('zh-hk')) {
			cols = 2; // 2 columns for jp and hk
		}
		var liPerCol = Math.ceil($lis.length/cols); // calculate <li>s per <ul>
		var max = 1;
		var min = 0;
		var myListItems = '<li id="column-li">';
		for (col=1;col<=cols;col++) { // for each column
			myListItems += '<ul class="column" id="column-'+col+'">'; // create a child <ul>
			max = col*liPerCol;
			min = max-liPerCol;
			max = max-1;
			$lis.each(function(ii) { // for each <li>
				if ( ii <= max && ii >= min ) {
					myListItems += '<li>'+$(this).html()+'</li>'; // append if it is in current <ul>
				}
			});
			myListItems += '</ul>';
		}
		myListItems += '</li>';
		$wrapper.html(myListItems).addClass('scrollable');
		$('.jScrollCap, .jScrollPaneTrack, .jScrollArrowUp, .jScrollArrowDown').remove();
		initScroll('#stage .scrollable'); // RE-initiate jScrollPane for popUpContent
	}


	//
	//	BRIDAL DIAMOND GUIDES (AWAITING VIDEO - 5 links to 4 layout)
	//	================================================================================================================================================
	if ( $('.sectionLinksAlt a').length > 0 ) {
		$('.sectionLinksAlt').addClass('sectionLinksAlt' + $('.sectionLinksAlt a').length);
	}


	//
	//	CUSTOM PAGINATION
	//	================================================================================================================================================
	if ( $('#pager').length > 0 ) {
		var pagesContent = 0;
		$("#pageData > div").each(function(i) {
			var s = i+1;
			if ($(this).children().length < 1) {
				$(this).remove(); // remove pages without content
				$("#pages > a[href='#"+s+"']").remove(); // remove page links without page content
			} else {
				pagesContent++;
			}
		});
		if (pagesContent == 1) { // single page so remove pager nav
			$('#pager').remove();
		} else {
			var $pH = $('#pageHolder');
			var $pD = $('#pageData');
			var $p = $('#pager');
			var $pS = $('#pages', $p);
			var $pSa = $('a', $pS);
			var $pn = $("a.next, a.prev", $p);
			$("a:first", $pS).addClass('sel');
			$pSa
				.bind('click', function(e) {
					e.preventDefault();
					e.returnValue = false;
					if (!$(this).hasClass('sel')) {
						var page = $(this).attr('href').replace('#','');
						$pSa.removeClass('sel hover');
						$(this).addClass('sel');
						$pn.removeClass('disabled');
						// Tracking SiteCatalyst - start
						try {sc_trackPage(page)} catch(err){}
						// Tracking SiteCatalyst - end
						if (page == 1) {
							$("a.prev", $p).addClass('disabled');
						} else if (page == $pSa.length) {
							$("a.next", $p).addClass('disabled');
						}
						$pH.html($("#page-"+page,$pD).html());
						initScroll('#pageHolder');
					}
				});
			$pn
				.bind('click', function(e) {
					e.preventDefault();
					e.returnValue = false;
					if (!$(this).hasClass('disabled')) {
						var cPage = $('.sel', $pS).attr('href').replace('#','');
						var newPage = parseInt( cPage, 10 )+1;
						if ($(this).hasClass('prev')) {
							newPage = parseInt( cPage, 10 )-1;
						}
						// Tracking SiteCatalyst - start
						try {sc_trackPage(newPage)} catch(err){}
						// Tracking SiteCatalyst - end
						$("#pages a[href='#"+newPage+"']").trigger('click'); /* can't just use .prev() or .next() because IE can't handle toffee */
					}
				});
		}
	}


	//
	//	SETTING SPIN + ZOOM
	//	================================================================================================================================================
	$('#settingsHolder a:first').addClass('hide');
	$('#zooms a:not(:first)').hide();
	$('#settingsHolder a')
		.bind('click', function(e) {
			e.preventDefault();
			e.returnValue = false;
			var page = $(this).attr('href').replace('#','');
			// Tracking SiteCatalyst - start
			sc_trackLink(page,'Setting');
			// Tracking SiteCatalyst - end
			$('#settingsHolder a').removeClass('hide');
			$(this).addClass('hide');
			$('#zooms a:not(#'+page+')').fadeOut("slow");
			$('#zooms a#'+page).fadeIn("slow");
		});


	//
	//	LOCATE A JEWELLER OVERIDE
	//	================================================================================================================================================
	$('#forevermark-main p.submitter input').removeAttr('onClick','').removeAttr('onclick',''); // remove default onclick handler


	//
	//	BRIDAL JEWELLERS
	//	================================================================================================================================================
	Object.isEmpty = function(obj) {
		for (var i in obj) {
			if (obj.hasOwnProperty(i)) {
				return false;
			}
		}
		return true;
	};
	function openDetailForm(link) {
		var that = $(link),
		bottomCarousel = $('#bottom-scroller'),
		detailForm = $('#form-holder'),
		linkOpen, linkClose;
		if (Object.isEmpty(that.data("linkText"))) {
			that.data("linkText", {open: that.text(), close: that.attr('rel')});
		}
		if (that.hasClass('close-jeweller')) {
			detailForm.fadeOut("slow", function() {
				bottomCarousel.animate({ top: 0 }, 1000);
				that.removeClass('close-jeweller').css('margin-top', '0').text(that.data("linkText").open);
			});
		} else {
			bottomCarousel.animate({ top: 155 }, 1000, function() {
				detailForm.fadeIn();
				that.addClass('close-jeweller').css('margin-top', '156px').text(that.data("linkText").close);
			});
		}
	}
	$('#bottom-scroller').css('top',0);
	$('#jeweller-middle .view-jeweller').bind('click', function(e) {
		e.preventDefault();
		openDetailForm(this);
	});


	//
	//	SET CLASS of 'last' to last item
	//	================================================================================================================================================
	$('#contentWrapper .sectionLinksAlt4 a:last').addClass('last');


	//
	//	LOCATE A JEWELLER
	//	================================================================================================================================================
	if ($('#your-diamonds img').length > 0 ) {
		$('#your-diamonds > div').removeClass('wrap');
	}


	//
	//	JEWELLER OPENING TIMES
	//	================================================================================================================================================
	if ($('body.jeweller #overlay-holder .js-toggle').length > 0 || $('body.locator #jeweller-results .js-toggle').length > 0) {
		contentToggle();
	}

	//
	// FOREVERMARK SETTING INTRO ANIMATION
	//
	var currentframe = 0;
	var fadeinspeed = 1500;
	var fadeoutspeed = 1500;
	var skipenabled = false;
	if (!$.browser.msie) {
		function animate_frame1() {
			currentframe = 1;
			$("#frame1container img").animate({
						opacity: 1.0,
						scale: '1.2'
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame1container h1").animate({
						opacity: 1.0,
						scale: '1.0'
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame2();
					});
		}
		function animate_frame2() {
			currentframe = 2;		
			$("#frame1container img").animate({
						opacity: 0.0,
						scale: '1.2'
					}, fadeoutspeed, function() {
						//Animation complete
					});
			$("#frame1container h1").animate({
						opacity: 0.0,
						scale: '1.0'
					}, fadeoutspeed, function() {
						//Animation complete
						if (skipenabled) {
							animate_frame7();
						} else {
							animate_frame3();
						}
					});
		}
		function animate_frame3() {
			currentframe = 3;		
			$("#frame2container img").animate({
						opacity: 1.0,
						scale: '1.2'
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame2container h1").animate({
						opacity: 1.0,
						scale: '1.0'
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame4();
					});
		}
		function animate_frame4() {
			currentframe = 4;		
			$("#frame2container img").animate({
						opacity: 0.0,
						scale: '1.2'
					}, fadeoutspeed, function() {
						//Animation complete
					});
			$("#frame2container h1").animate({
						opacity: 0.0,
						scale: '1.0'
					}, fadeoutspeed, function() {
						//Animation complete
						if (skipenabled) {
							animate_frame7();
						} else {						
							animate_frame5();
						}
					});
		}
		function animate_frame5() {
			currentframe = 5;		
			$("#frame3container img").animate({
						opacity: 1.0,
						scale: '1.2'
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame3container h1").animate({
						opacity: 1.0,
						scale: '1.0'
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame6();
					});	
		}
		function animate_frame6() {
			currentframe = 6;
			$("#frame3container img").animate({
						opacity: 0.0,
						scale: '1.2'
					}, fadeoutspeed, function() {
						//Animation complete					
					});
			$("#frame3container h1").animate({
						opacity: 0.0,
						scale: '1.0'
					}, fadeoutspeed, function() {
						//Animation complete
						$("#skip").attr('style','display:none;');
						animate_frame7();
					});
		}
		function animate_frame7() {
			currentframe = 7;		
			$("#frame4container img, #frame4container h1, #frame4container p").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});	
		}
	} else {
		function animate_frame1_ie() {
			currentframe = 1;
			$("#frame1text").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame1image").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame2_ie();
					});
		}
		function animate_frame2_ie() {
			currentframe = 2;
			$("#frame1text").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
					});
			$("#frame1image").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
						if (skipenabled) {
							animate_frame7_ie();
						} else {							
						    animate_frame3_ie();
						}
					});
		}
		function animate_frame3_ie() {
			currentframe = 3;
			$("#frame2text").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame2image").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame4_ie();
					});
		}
		function animate_frame4_ie() {
			currentframe = 4;
			$("#frame2text").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
					});
			$("#frame2image").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
						if (skipenabled) {
							animate_frame7_ie();
						} else {							
						    animate_frame5_ie();
						}
					});
		}
		function animate_frame5_ie() {
			currentframe = 5;
			$("#frame3text").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#frame3image").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
						animate_frame6_ie();
					});
		}
		function animate_frame6_ie() {
			currentframe = 6;
			$("#frame3text").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
					});
			$("#frame3image").animate({
						opacity: 0.0
					}, fadeoutspeed, function() {
						//Animation complete
						$("#skip").attr('style','display:none;');						
						animate_frame7_ie();
					});
		}
		function animate_frame7_ie() {
			currentframe = 7;
			$("#frame4container").show();
			$("#frame4container").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});			
			$("#contentWrapper p").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
					});
			$("#contentWrapper h1").animate({
						opacity: 1.0
					}, fadeinspeed, function() {
						//Animation complete
						//animate_frame8_ie();
					});
		}
		function animate_frame1_ie6() {
			currentframe = 1;
			$("#frame1container").fadeIn(fadeinspeed).fadeOut(fadeoutspeed);
			$("#frame2container").delay(fadeinspeed + fadeoutspeed).fadeIn(fadeinspeed).fadeOut(fadeoutspeed);
			$("#frame3container").delay((fadeinspeed + fadeoutspeed)*2).fadeIn(fadeinspeed).fadeOut(fadeoutspeed);
			$("#frame4container").delay((fadeinspeed + fadeoutspeed)*3).fadeIn(fadeinspeed);
			$("#skip").delay((fadeinspeed + fadeoutspeed)*3).fadeOut(fadeoutspeed);
		}
	}
	function showForevermarkSettingAnimationDelayed() {
		if ( $('#frame1container img').length > 0 ) {
			if (!$.browser.msie) {
				setTimeout(function() {
					animate_frame1();
				}, 1000);
			} else {
				setTimeout(function() {
					animate_frame1_ie();
				}, 1000);
			}
		}
	}
	function showForevermarkSettingAnimation() {
		if ( $('#frame1container img').length > 0 ) {
			if ($.browser.msie) {
				if ($.browser.version > 6) {
					$("#frame1container").css('opacity', 100);
					$("#frame2container").css('opacity', 100);
					$("#frame3container").css('opacity', 100);
					$("#frame1text").css('opacity', 0);
					$("#frame2text").css('opacity', 0);
					$("#frame3text").css('opacity', 0);
					$("#frame1image").css('opacity', 0);
					$("#frame2image").css('opacity', 0);
					$("#frame3image").css('opacity', 0);
					$("#frame4container").hide();
					animate_frame1_ie();
				} else {
					$("#frame1container").attr('style','display:block;');
					$("#frame2container").attr('style','display:block;');
					$("#frame3container").attr('style','display:block;');
					$("#frame4container").attr('style','display:block;');
					$("#frame1container img").css('opacity', 100);
					$("#frame2container img").css('opacity', 100);
					$("#frame3container img").css('opacity', 100);
					$("#frame1container").hide();
					$("#frame2container").hide();
					$("#frame3container").hide();
					$("#frame4container").hide();
					animate_frame1_ie6();
				}
			} else {
				animate_frame1();
			}
		}
		$('#contentWrapper #skip a').bind('click', function() {
			$("#skip").attr('style','display:none;');
			//$("#contentWrapper").stop();
			skipenabled = true;
			if ($.browser.msie && $.browser.version <= 6) {
				$("#frame1container").dequeue();
				$("#frame2container").dequeue();
				$("#frame3container").dequeue();
				$("#frame4container").dequeue();
				$("#frame1container").hide();
				$("#frame2container").hide();
				$("#frame3container").hide();
				$("#frame4container").fadeIn(fadeinspeed);
			}
		});
	}

});
