/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	Preload some images for a cleaner build
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$.preloadImages("../assets/img/jpg/background-tile.jpg", "../assets/img/png/rcCorners.png", "../assets/img/png/slideshowLR.png", "../assets/img/png/rcSidesLR.png", "../assets/img/png/rcSidesTB.png", "../assets/img/png/footer-bracket.png", "../assets/img/png/text/new-arrivals-nextarrow_ov.png", "../assets/img/png/text/new-arrivals-backarrow_ov.png");


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	simple image loading function
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
function setImgSrc(id,img) {
	document.getElementById(id).src = img;
}


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	Hide email addresses
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
function hideEmail(name,domain,text){
	if (text == '') { text=name+'@'+domain; }
	var a="<a href='mailto:";
	var b=name+"@"+domain+"' class='linkEmail'>";
	var c=text;
	var d="</a>";
	document.write(a+b+c+d);
}


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	Handle splashRotater navigation - must be out of
	jquery framework or odd things will happen
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */	

var t = 0;
var text = new Array(5);
text[1]  = new Array(3);
text[2]  = new Array(3);
text[3]  = new Array(3);
text[4]  = new Array(3);
text[5]  = new Array(3);

text[1][1] = '<h2>Alles flattert</h2><p>Farben inspirieren.  Kristalle gl&#228;nzen. W&#228;hlen Sie eine Farbe, einen Stil oder ein Thema aus und machen Sie es zu Ihrem eigen. Sie werden bezaubert sein.</p>';
text[1][2] = '<h2>Tout vibre</h2><p>Un style ou un thème et faites en le votre.  Vous en serez séduite.</p>';

text[2][1] = '<h2>Tauchen Sie ein</h2><p>Bringen Sie Ihre Fantasie ins Spiel mit  Kreationen aus traditionellem Murano Glas aus Italien. Gestaltet  um Licht einzufangen und ein Mosaik aus hellen und satten Farben auf einmal zu reflektieren.</p>';
text[2][2] = '<h2>Entrez dans l’univers</h2><p>Introduisez votre propre fantaisie dans vos créations avec le traditionnel verre de Murano d’Italie. Créez pour capturer les lumières, afin que reflètent les couleurs riches et claires en forme de mosaïque.</p>';

text[3][1] = '<h2>Denn sie ist Ihr Ein und Alles!</h2><p>Sie hat immer Zeit f&#252;r andere und an sich selbst denkt sie zuletzt. Denken Sie an diesem Muttertag zu allererst an Ihre Mutter. Schenken Sie ihr ein Chamilia-Armband, das genauso sch&#246;n und einzigartig ist, wie Ihre Mutter.</p>';
text[3][2] = '<h2>Elle est Votre Seule , Votre Unique.</h2><p>Elle est toujours à l’écoute des autres, pour ne penser à soi qu’en dernier. Pour cette Fête des Mères, pensez avant tout à Votre Maman. Offrez- lui un bracelet Chamilia, qui est aussi unique et joli que votre Maman.</a>';

text[4][1] = '<h2>Erforsche unsere neue Disney Kollektion</h2><p>Mickey, Tinkerbell (Fee Gl&#246;ckchen), Donald and Pooh.Die Besetzung von Charakteren, um sie in Erinnerung zu behalten. Exklusiv nur bei Chamilia erh&#228;ltlich.</p>';
text[4][2] = '<h2>Explore our Disney Collection</h2><p>Mickey, la F&#233;e clochette, Donald et Winnie l\'Ourson. Les pendeloques Disney exclusives de Chamilia. Le casting de caractere pour bien les garder en souvenir.</p>';

text[5][1] = '<h2>Your Life. Your Style.</h2><p>Entdecke die Chamilia Beads, die so einmalig sind wie Du.</p><a class="arrowLink" href="?page=inspiration">Besuche die Design Inspirationen</a>';
text[5][2] = '<h2>Votre vie, votre style</h2><p>D&#233;couvrez toutes les possibilit&#233;s pour exprimer votre style personnel.</p><a class="arrowLink" href="?page=inspiration">View Design Inspirations</a>';

function rotateSplash(id, rd) {
	clearTimeout(t);
	$('#splashRotator #srType').fadeOut('slow')
	$('#splashRotator #srBackground').fadeOut('slow', function() {
		
	$('#splashRotator #srBackground').css('background-position','7px 37px');
	$('#splashRotator #srBackground').css('backgroundImage','url(../assets/img/jpg/splashpage-'+id+'.jpg)');
		
		var j = 1;
		if (l == 'de')
		{
			j = 1;
		}
		else if (l == 'fr')
		{
			j = 2;
		}
		
		$(this).delay(120,function(){
			resetButtons(id);
			
			var srtype = text[id][j];
			
			$('#splashRotator #srType').html(srtype);
			$('#splashRotator #srBackground').fadeIn('slow');
			$('#splashRotator #srType').fadeIn('slow',function() {
				if (rd > 0) {
					setTimeout("srTimer("+id+")",rd);
				}
			});
		});
	});
}

function resetButtons(id) 
{
	//5 buttons
	$('#srControls #button1').css({backgroundPosition: '0 0'});
	$('#srControls #button2').css({backgroundPosition: '0 0'});
	$('#srControls #button3').css({backgroundPosition: '0 0'});
	$('#srControls #button4').css({backgroundPosition: '0 0'});
	$('#srControls #button5').css({backgroundPosition: '0 0'});
	
	$('#srControls #button' + id).css({backgroundPosition: '0 -12px'});
}

function srTimer(id) {
	id++;
	//5 splashes
	if (id > 5) id = 1;
	if (id == 3) id = 4;	//skip 3
	t=setTimeout("rotateSplash("+id+",1)",4000);
}


function changeview(id,view) {
	if (view == 'flat') {
		$('#angleView').removeClass('changeLinkSelected');
		$('#flatView').addClass('changeLinkSelected');
		$('#ang'+id).fadeOut('slow',function(){
			$('#flat'+id).fadeIn('slow');
		});
	} else {
		$('#flatView').removeClass('changeLinkSelected');
		$('#angleView').addClass('changeLinkSelected');
		$('#flat'+id).fadeOut('slow',function(){
			$('#ang'+id).fadeIn('slow');
		});
	}
}


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	Handle featured bead navigation
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */	
 
function beadnav(current,next) {
	current = document.getElementById('series'+current);
	next = document.getElementById('series'+next);
	$(current).fadeOut('slow', function() {
		$(next).fadeIn('slow');
	});
}
 
		 
		 
		 

$(document).ready(function() {		
						   
		$('a.lightbox').lightbox();
		
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion>=8)
				browserName = 'IE8';
			else if (ieversion>=7)
				browserName = 'IE7';
			else if (ieversion>=6)
				browserName = 'IE6';
			else if (ieversion>=5)
				browserName = 'IE5';
		} else 
			browserName = 'ok';
			
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Show and hide the tooltips for the beads.
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
		 
		$('#splashpage #showcase10 li').hover( 
			function() 
			{
				
				var tooltip = $('.tt', this);
				var tooltipBottom = $('.tt .brow .bc', this);
				var docWidth = $(document).width();
				var mainContainerWidth = $('#main-container').width();				
									
				// take into account that ul#showcase10 is 18 pixels right of the main-container's left edge
				var extraSpaceForShadow = 18; 
				
				tooltip.show(); // needed for correct position reading
				var posL = $(this).position().left + parseFloat( $(this).parent().css("margin-left").replace(/px/, '') ) + extraSpaceForShadow;
				tooltip.hide();
				
				var distToScreenLeft = posL + ( ( docWidth - mainContainerWidth ) / 2 ) - $(document).scrollLeft();
				
				// right margin fix for IE
				if (browserName=="IE6") {
					var iemarginfix = 80;
				} else if (browserName=="IE7") {
					var iemarginfix = 80;
				} else {
					var iemarginfix = 10;
				}
				
				if ( docWidth - mainContainerWidth == 0 ) // scrollbars
				{ 
					var distToScreenRight = $(document).scrollLeft() + $(window).width() - ( posL + $(this).width() ) - iemarginfix;
				} 
				else //no scrollbars
				{				
					var distToScreenRight = $(document).width() - ( distToScreenLeft + $(this).width() ) - iemarginfix;
				}
				
				var tooltipHalfWidth = tooltip.width()/2;
				var offsetX = 0;
				if ( distToScreenLeft < tooltipHalfWidth ) offsetX += ( tooltipHalfWidth - distToScreenLeft );
				if ( distToScreenRight < tooltipHalfWidth ) offsetX -= ( tooltipHalfWidth - distToScreenRight );
				
				// margin left limits based on eyeballing
				// MAX LEFT:  -10 
				// MAX RIGHT: -425
				// CENTERED:  -212
				// (changes based on layout of tooltip image - where the left begins)								
				var marginLeft = -212 + offsetX;
					if ( marginLeft > -10 ) marginLeft = -10;
					else if ( marginLeft < -425 ) marginLeft = -425;
				
				// background position limits based on eyeballing
				// MAX LEFT:  -498  / tooltip.png is 1016 px wide with 9px on each side for dropshadow area, (1016 - 9*2)/2 = 498
				// MAX RIGHT: -75
				// CENTER:    -286 or -287
				var bgPosition = -287 - offsetX;
					if ( bgPosition > -75 ) bgPosition = -75;
					else if ( bgPosition < -498 ) bgPosition = -498;				
			
				tooltip.css('margin-left', marginLeft + 'px');				
				tooltipBottom.css('background-position', bgPosition + 'px bottom');
				tooltip.fadeIn(150);
			}, 
			function() 
			{ 
				$('.tt', this).fadeOut(20);
			}
		);
		
		
		$('#splashpage #showcase10 li img').click(		
			function(event) 
			{
				event.preventDefault();
			}
		);
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Show and hide the tooltips for the Email.
			Block showcase10 with blockUI plugin.
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
		 
		$('#fnav-email').click( 
			function(event) 
			{
				event.preventDefault();
				if (browserName!="IE6") $('#showcase10').block();
				$('.tt', '#fnav-globalwebsite').hide();
				$('.tt', this).fadeIn(400);
				$('.footerLinks', this).addClass('tooltipVisibleTextHover');
			}
		);
		
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Show and hide the tooltips for the Global Website.
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
		 
		$('#fnav-globalwebsite').click( 
			function(event) 
			{
				event.preventDefault();
				if (browserName!="IE6") $('#showcase10').block();
				$('.tt', '#fnav-email').hide();
				$('.tt', this).fadeIn(400);
				$('.footerLinks', this).addClass('tooltipVisibleTextGlobeHover');
			}
		);
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Handle close window icons
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
		
		$('#fnav-email .closewin').click(function()
			{
				$('#fnav-email .footerLinks').removeClass('tooltipVisibleTextHover');
				$('#fnav-globalwebsite .footerLinks').removeClass('tooltipVisibleTextGlobeHover');
				$('#showcase10').unblock();
				$('.tt').fadeOut('fast');
				return false;
			}
		);
		
		$('#fnav-globalwebsite .closewin').click(function()
			{
				$('#fnav-email .footerLinks').removeClass('tooltipVisibleTextHover');
				$('#fnav-globalwebsite .footerLinks').removeClass('tooltipVisibleTextGlobeHover');
				$('#showcase10').unblock();
				$('.tt').fadeOut('fast');
				return false;
			}
		);	
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Hide footer bubbles when other content is clicked.
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
		 
		$('.main-content').click( 
			function() 
			{
				$('#fnav-email .tt').hide();
				$('#fnav-globalwebsite .tt').hide();
				$('#fnav-email .footerLinks').removeClass('tooltipVisibleTextHover');
				$('#fnav-globalwebsite .footerLinks').removeClass('tooltipVisibleTextGlobeHover');
				$('#showcase10').unblock();
			}
		);
		 
		$('#showcase10').click( 
			function() 
			{
				$('#fnav-email .tt').hide();
				$('#fnav-globalwebsite .tt').hide();
				$('#fnav-email .footerLinks').removeClass('tooltipVisibleTextHover');
				$('#fnav-globalwebsite .footerLinks').removeClass('tooltipVisibleTextGlobeHover');
				$('#showcase10').unblock();
			}
		);
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			Submit E-mail Form
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */		 

		 $('#fnav-email .tt dl dd .arrowLink').hover(		
			function() 
			{
				$(this).css("cursor", "pointer");
			},
			function() 
			{
				$(this).css("cursor", "default");				
			}			
		);
		
		 $('#fnav-email .tt dl dd .arrowLink').click(		
			function() {
				document.emailform.submit();
			}
		);
		
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
			rotateSplash: initialize buttons and start timer
		 - - - - - - - - - - - - - - - - - - - - - - - - - - - - */	
		resetButtons(1);
		srTimer(1);

		//5 buttons
		$('#srControls #button1').click(function(event){
				event.preventDefault();
				rotateSplash(1,0);
		});
		$('#srControls #button2').click(function(event){
				event.preventDefault();
				rotateSplash(2,0);
		});
		/*$('#srControls #button3').click(function(event){
				event.preventDefault();
				rotateSplash(3,0);
		});*/
		$('#srControls #button4').click(function(event){
				event.preventDefault();
				rotateSplash(4,0);
		});
		$('#srControls #button5').click(function(event){
				event.preventDefault();
				rotateSplash(5,0);
		});
		
	}
);