// JavaScript Document

//Browser.Plugins.Flash.version
//Browser.Plugins.Flash.build

var correctFlashInstalled = false

if(Browser.Plugins.Flash.version > 9){
	correctFlashInstalled = true
	
}else if(Browser.Plugins.Flash.version == 9){
	if(Browser.Plugins.Flash.build >= 115){
		correctFlashInstalled = true
	}
}

var onIPhone = false
if(Browser.Platform.ipod){
	onIPhone = true
}
var quicktimeInstalled = false;

if (navigator.plugins) {
  for (i=0; i < navigator.plugins.length; i++ ) {
	   if (navigator.plugins[i].name.indexOf("QuickTime") >= 0)
			{ quicktimeInstalled = true; }
	}
}

Browser.Plugins.Quicktime = quicktimeInstalled;

var relativeLink = function(url){
	return '/'+url.split('/').splice(3).join('/')
}
var getSection = function(url){
	return url.split('#')[0]
}

/*
var initFlashHeader = function(){
	
	if(correctFlashInstalled){
		
		var headerImages = [];
		
		var objs = $$('div#headertopimage img')
		
		objs.each(function(item, index){
			headerImages.push(item.getProperty('src'))
			//alert(index + " = " + item);
		});
		
		var headerObj = new Swiff('/assets/flash/headershow.swf', {
			id: 'headerShow',
			width: 829,
			height: 217,
			container: 'headertopimage',
			params: {
				wmode: 'transparent',
				salign: 'LT',
				scale: 'noscale',
				bgcolor: '#fff',
				menu: 'false'
			},
			vars: {
				images: headerImages.join(','),
				slideTime: 3000
			},
			callBacks: {
				//load: myOnloadFunc
			}
		});
		
	}	
}
*/

var initScroller = function(obj,prev,next,block){
	
	
	var scollerObj = $(obj);
	
	var maxScroll = scollerObj.getSize().y;
	var scrollOffset = Math.ceil(maxScroll/block);
	var scrollStep = block-50;
	
	scollerObj.setStyles({'height':block,'overflow':'hidden'})
	
	var myFx = new Fx.Scroll(scollerObj,{
		onComplete: function(){
			var h1s = scollerObj.getChildren('h1');
			h1s.each(function(item, index){
				if(item.getPosition().y > 0){
					item.setStyle('visibility','visible');
				}
			});
		},
		onStart: function(){
			var h1s = scollerObj.getChildren('h1');
			h1s.each(function(item, index){
							  
				item.setStyle('visibility','hidden');
				
			});
		}
	});
	
	var scollerPrevObj = $(prev);
	scollerPrevObj.addEvents({
		'click': function(){
			myFx.start(0, scollerObj.getScroll().y-scrollStep);
			
			if(scollerObj.getScroll().y-scrollStep <= 0){
				scollerPrevObj.fade('out')
			}else{
				scollerPrevObj.fade('in')
			}
			if(scollerObj.getScroll().y-scrollStep >= maxScroll){
				scollerNextObj.fade('out')
			}else{
				scollerNextObj.fade('in')
			}
			
			return false;
		}
	});
	
	var scollerNextObj = $(next);
	scollerNextObj.addEvents({
		'click': function(){
			myFx.start(0, scollerObj.getScroll().y+scrollStep);
			
			if(scollerObj.getScroll().y+scrollStep <= 0){
				scollerPrevObj.fade('out')
			}else{
				scollerPrevObj.fade('in')
			}
			if(scollerObj.getScroll().y+scrollStep > (maxScroll-scrollStep)){
				scollerNextObj.fade('out')
			}else{
				scollerNextObj.fade('in')
			}
			
			return false;
		}
	});
	
	scollerPrevObj.fade('hide')
	
}
var initExternalLinks = function(){
	
	var objs = $$('a[rel^=external]');
	
	objs.each(function(item, index){
		item.set('target','_blank');
	});
	
}

var DesireMeLogoLink = "/desireme/"+localeShort+"/get-your-free-sample/";
var IncredibleMeLogoLink = "/desireme/"+localeShort+"/get-your-free-sample/";

if(localeShort == 'ru'){
	DesireMeLogoLink = "/desireme/"+localeShort+"/";
	IncredibleMeLogoLink = "http://www.escada-fragrances.com/incredibleme/ru/";
}

var initIncredibleMeImage = function(){
	
	
	/*
	var html = $('pagecontent').get('html');
	html = html.split(lookFor).join(replaceWith);
	$('pagecontent').set('html', html);
	*/
	
	var lookFor = "IncredibleMe";
	
	var replaceWith = "<a href=\""+IncredibleMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/incredible-me.png\" alt=\"Incredible Me\" width=\"66\" height=\"12\" style=\"margin-bottom:-2px;display:inline;\" /></a>";
	var replaceWithSpan = "<a href=\""+IncredibleMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/incredible-me.png\" alt=\"Incredible Me\" width=\"66\" height=\"12\" style=\"margin-bottom:0px;display:inline;\" /></a>";
	
	var replaceWithNoLink = "<img src=\"/desireme/assets/images/global/incredible-me-14.png\" width=\"66\" height=\"14\" alt=\"Incredible Me\" style=\"margin-bottom:-3px;display:inline-block;\" />";
	var replaceWithSpanNoLink = "<img src=\"/desireme/assets/images/global/incredible-me.png\" width=\"66\" height=\"12\" alt=\"Incredible Me\" style=\"margin-bottom:0px;display:inline;\" />";
	
	
	var objs = $$("p:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWithNoLink);
		item.set('html', html);
	});
	
	var objs = $$("p:contains('"+lookFor+"')");
	objs.each(function(item, index){
				//alert(item.getParent().getParent().get('id'))
		var html = item.get('html');
		if(item.getParent().getParent().get('id') != 'findoutmore'){
			html = html.split(lookFor).join(replaceWith);
		}else{
			html = html.split(lookFor).join(replaceWithNoLink);
		}
		item.set('html', html);
	});
	
	var objs = $$("span:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWithSpan);
		item.set('html', html);
	});
	
	var objs = $$("span:contains('"+lookFor+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWithSpan);
		item.set('html', html);
	});
	
	var replaceWith = "<a href=\""+IncredibleMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/incredible-me-13.png\" width=\"72\" height=\"13\" alt=\"Incredible Me\" style=\"margin-bottom:-3px;display:inline;\" /></a>";
	var replaceWith2 = "<img src=\"/desireme/assets/images/global/incredible-me-13.png\" width=\"72\" height=\"13\" alt=\"Incredible Me\" style=\"margin-bottom:-3px;display:inline;\" />";
	
	var objs = $$("h2:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith2);
			item.set('html', html);
		}
	});
	
	var objs = $$("h2:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff"  ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith2);
			item.set('html', html);
		}
	});
	
	var objs = $$("h3:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var objs = $$("h3:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff"  ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
}
var initDesireMeImage = function(){
	
	var lookFor = "DesireMe";
	//var replaceWith = "<a href=\"/desireme/"+localeShort+"/get-your-free-sample/\"><span style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/desireme/assets/images/global/desire-me.png');width:53px;height:11px;display:inline:block;\"><img src=\"/desireme/assets/images/global/desire-me.png\" width=\"53\" height=\"11\" alt=\"Desire Me\" style=\"filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);\" /></span></a>";
	//var replaceWith = "<a href=\"/desireme/"+localeShort+"/get-your-free-sample/\"><img src=\"/desireme/assets/images/global/desire-me.gif\" alt=\"Desire Me\" /></a>";
		
	var replaceWith = "<a href=\""+DesireMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/desire-me.png\" width=\"53\" height=\"11\" alt=\"Desire Me\" style=\"display:inline;\" /></a>";
	
	var objs = $$("p:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	var objs = $$("p:contains('"+lookFor+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	
	var objs = $$("span:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	var objs = $$("span:contains('"+lookFor+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	var replaceWith = "<a href=\""+DesireMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/desire-me-h1-12-fbf2d5.png\" width=\"60\" height=\"13\" alt=\"Desire Me\" style=\"margin-bottom:-2px;display:inline;\" /></a>";
	
	var objs = $$("h1:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#fbf2d5" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var objs = $$("h1:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if(String(item.getStyle('color')).toLowerCase() == "#fbf2d5" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var replaceWith = "<a href=\""+DesireMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/desire-me-h1-12-ffffff.png\" width=\"60\" height=\"13\" alt=\"Desire Me\" style=\"margin-bottom:-3px;display:inline;\" /></a>";
	
	var objs = $$("h1:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff"  ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var objs = $$("h1:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var replaceWith = "<a href=\""+DesireMeLogoLink+"\" style=\"display:inline;\"><img src=\"/desireme/assets/images/global/desire-me-h1-12-ffffff.png\" width=\"60\" height=\"13\" alt=\"Desire Me\" style=\"margin-bottom:-3px;\" /></a>";
	var replaceWith2 = "<img src=\"/desireme/assets/images/global/desire-me-h1-12-ffffff.png\" width=\"60\" height=\"13\" alt=\"Desire Me\" style=\"margin-bottom:-3px;\" />";
	
	var objs = $$("h2:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff"  ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith2);
			item.set('html', html);
		}
	});
	
	var objs = $$("h2:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith2);
			item.set('html', html);
		}
	});
	
	var objs = $$("h3:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff"  ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
	
	var objs = $$("h3:contains('"+lookFor+"')");
	objs.each(function(item, index){
		if( String(item.getStyle('color')).toLowerCase() == "#ffffff" || String(item.getStyle('color')).toLowerCase() == "#fff" ){
			var html = item.get('html');
			html = html.split(lookFor).join(replaceWith);
			item.set('html', html);
		}
	});
}
var initOceanLoungeImage = function(){
	
	var lookFor = "OceanLounge";
	var replaceWith = "<img src=\"/desireme/assets/images/global/ocean-lounge.png\" width=\"155\" height=\"11\" alt=\"Ocean Lounge\" />";
	
	var objs = $$("p:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	var objs = $$("p:contains('"+lookFor+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	
	var objs = $$("span:contains('"+lookFor.toUpperCase()+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
	
	var objs = $$("span:contains('"+lookFor+"')");
	objs.each(function(item, index){
				
		var html = item.get('html');
		html = html.split(lookFor).join(replaceWith);
		item.set('html', html);
	});
}
var initNavLinks = function(){
	
	var objs = $$('div#navigation ul li');
	var pagePath = window.location.href.split('/').splice(5).join('/');
	
	var msg = ""
	//msg += "<br/>"+pagePath
	
	if(pagePath.length > 1){
		objs.each(function(item, index){
			var linkObj = item.getChildren('a')[0];
			var href = linkObj.href.split('/').splice(5).join('/');
			//msg += "<br/>"+href
			if(href.length > 1 && pagePath.indexOf(href) != -1){
				linkObj.set('class','active');
				var lookFor = '\u203A'; //&rsaquo;
				//msg += "<br/>"+escape(linkObj.get('html'))
				linkObj.set('html',linkObj.get('html').split(lookFor).join(''));
				linkObj.set('html',linkObj.get('html').split(lookFor.toUpperCase()).join(''));
			}
		});
	}else{
		var linkObj = objs[0].getChildren('a')[0];
		linkObj.set('class','active');
	}
	//$('bottle').set('html',msg);
	
	/*
	var objs = $('mainnav').getChildren('li');
	
	objs.each(function(item, index){
		if(item.getChildren('ul.subnav').length > 0){
			item.getChildren('ul.subnav')[0].setStyles(	{'margin-left':(item.getPosition().x)-37}								
														);
			
			item.addEvents({
				'mouseover': function(){
					//alert('mouseover');
					item.getChildren('ul.subnav')[0].setStyle('visibility','visible');
				},
				'mouseleave': function(){
					//alert('mouseover');
					item.getChildren('ul.subnav')[0].setStyle('visibility','hidden');
				},
				'click': function(){
					//alert('click');
				}
			});
			
		}
	});
	*/
	
}
window.addEvent('domready', function() {
	
	
	initExternalLinks();
	
	
	initDesireMeImage();
	//initOceanLoungeImage();
	initIncredibleMeImage();
	
	if( localeShort != 'ru' && localeShort != 'ar' ){
	
		<!-- Cufon Font Replacment //-->
		Cufon.replace('div#column02textscrollerup', { fontFamily: 'Futura Medium' });
		Cufon.replace('div#column02textscrollerdown', { fontFamily: 'Futura Medium' });
		Cufon.replace('a[rel=FuturaMedium]', { fontFamily: 'Futura Medium' , hover: true });
	
		Cufon.replace('h1', { fontFamily: 'Futura Medium' });
		Cufon.replace('h2', { fontFamily: 'Futura Medium' });
		Cufon.replace('h3', { fontFamily: 'Futura Medium' });
		
		<!-- Cufon Font Replacment //-->
		Cufon.replace('div#navigation ul li a', { fontFamily: 'Futura Medium', hover: true } );
	}
	
});



/*
Cufon.replace('h1', { fontFamily: 'Futura_Medium' });
Cufon.replace('h2', { fontFamily: 'Futura_Medium' });
//Cufon.replace('#content > h1:first-child', { fontFamily: 'ITC Tiffany Demi' });
			
Cufon.replace('p', { fontFamily: 'Futura_Medium' });
Cufon.replace('label', { fontFamily: 'Futura_Medium' });
*/

<!--END //-->