/* - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	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(3);
text[1]  = new Array(3);
text[2]  = new Array(3);
text[3]  = new Array(3);

text[1][1] = '<h2>MISS CHAMILIA</h2>';
text[1][2] = '<h2>MISS CHAMILIA</h2>';

text[2][1] = '<h2>Das Elixier des Gl&#252;cks</h2><p>Der Anh&#228;nger in Tropfenform aus Sterlingsilber an einer Kordel aus handgef&#228;rbter Seide. Mit einem speziell konzipierter Zug l&#228;sst sich die L&#228;nge der Halskette verstellen F&#252;gen Sie Beads in Farben und Formen ganz nach Ihrem Wunsch ein, und so entsteht das ganz pers&#246;nliche Gl&#252;ckselixier.</p>';
text[2][2] = '<h2>L&#39;élixir du bonheur</h2><p>Un pendentif en argent fin en forme de goutte, suspendu à une cordelette en soie teinte à la main. Conçu permet de régler la longueur du collier. Choisissez les formes et les couleurs de pendeloques que vous préférez et faites-en votre collier du bonheur.</p>';

text[3][1] = '<h2>Ein Hauch von Glamour mit Tradition</h2><p>Chamilia pr&auml;sentiert als Weltpremiere die einzigartige SIENA COLLECTION. Die Kreationen aus 14Kt Rose- und Gelbgold sowie Sterling Silber wurden mit brillanten Swarovski Kristallen bereichert und harmonieren perfekt mit den Farben und Trends der Saison.  </p>';
text[3][2] = '<h2>Une touche de glamour se m&ecirc;le &agrave; la tradition</h2><p>Chamilia pr&eacute;sente en avant-premi&egrave;re  l&#39;unique COLLECTION SIENA.  Les cr&eacute;ations r&eacute;alis&eacute;es en or rose,  or jaune  14ct et en argent sterling ont &eacute;t&eacute; sertient de cristaux Swarovski brillants qui s&#39;accordent parfaitement aux couleurs et aux tendances de la saison.</p>';



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) 
{
	//3 buttons
	$('#srControls #button1').css({backgroundPosition: '0 0'});
	$('#srControls #button2').css({backgroundPosition: '0 0'});
	$('#srControls #button3').css({backgroundPosition: '0 0'});
	
	$('#srControls #button' + id).css({backgroundPosition: '0 -12px'});
}

function srTimer(id) {
	id++;
	//5 splashes
	if (id > 3) 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);
		});

		
	}
);
