/* Author:
 Antoine Wette
 Biedermann und Brandstift creative services

 Parts by Hirbod Mirjavadi
 Biedermann und Brandstift creative services
 */

var	myScrollLeft = {},
	myScrollMiddle = {};

(function(a) {
	jQuery.browser.mobile = /android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))
})(navigator.userAgent || navigator.vendor || window.opera);

$(window).load(function() {

	$.getScript('js/metascript.js', function(data, textStatus) {
		new_ggl.init();
	});
	//ggl.init();
	//if (jQuery.browser.mobile ){
	if(jQuery.browser.mobile && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 5_\d/i) && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 4_\d/i)) {
		// MOBILE DEVICES
		
		$('body').addClass('mobile-not-supported').html('<span><h1>SORRY</h1><p>THIS SITE IS NOT (YET) OPTIMIZED FOR YOUR DEVICE/BROWSER.<br />PLEASE USE A DESKTOP BROWSER SO FAR...</p></span>');
		$('#columns_wrapper').css('display', 'none!important');
		$('html').addClass('mobile-oldies');
				
		/*
		 $.getScript('js/iscroll-lite.js', function(data, textStatus){
		 	myScroll = new iScroll('bags_scroller');

		 });
		 */
		//myScrollLeft = new iScroll('bags_scroller');
		//$('html').addClass('mobile-oldies');
	
		//ggl.init();
		
	} else if(navigator.userAgent.match(/(iPhone);.*CPU.*OS 5_\d/i) || navigator.userAgent.match(/(iPhone);.*CPU.*OS 4_\d/i)) {
		// IPHONE		
		ggl.init();
		
	} else if(($('html').hasClass('oldie') && !$('html').hasClass('ie8')) || (!Modernizr.cssanimations && !navigator.userAgent.match(/MSIE/i)) || (!Modernizr.hashchange && !navigator.userAgent.match(/Version\/4\.\d/i)) ) {
		$('body').addClass('oldies-not-supported').html('<span><h1>SORRY, TOO OLD*</h1><p>*Your Browser Of Course<br/>Please UPDATE!</p></span>');
		$('#columns_wrapper').css('display', 'none!important');
		// BLOCK FOR OLD BROWSER EXCEPT FOR IE8
	} else {
		// DESKTOP BROWSER	
			
		ggl.init();
	}
	

	//alert(jQuery.browser.mobile);
});
$(window).resize(function() {
	ggl.resize();
});
var canvasVideoPlaying = {};
var ggl = ( function(win) {
	var windowHeight, touchSlideshow = {}, zoomBlocked = false, deepLinkFirst = true, touchSlideshow2 = {}, windowWidth, $window = $(window), activePost = 0, moreStories = true, scrollWrapper = $('#container'), lineName = '', lineModels = new Array(), lineColors = new Array(), hightLightColor = '', linePathPrefix = '', currentColor = 0, currentModel = 0, zoomTouchClass = {}, currentColumn = 'middle', theBags_color, theBags_bg, zoomMLeft = 0, zoomMTop = 0, zoomLoaded = false, loadingMoreStories = false, redaxoImgType = '', redaxoCurrentImgWidth = 0, storyImgRatio = 1.84, reflectionOffset = -92, showStoriesLink = 'en/bags/the-stories', showCollectionLink = 'en/bags/collection12012',
	// BAG SLIDESHOW
	animatingBag = false, slideshowTransitionendHandler = function() {
		
		document.getElementById('slideshow_next').removeEventListener("webkitTransitionEnd", arguments.callee);
		document.getElementById('slideshow_next').removeEventListener("transitionend", arguments.callee);
		document.getElementById('slideshow_next').removeEventListener("oTransitionEnd", arguments.callee);
		document.getElementById('slideshow_next').removeEventListener("msTransitionEnd", arguments.callee);

		$('#slideshow_current, #slideshow_next').css({
			'-webkit-transition' : 'none',
			'-moz-transition' : 'none',
			'-o-transition' : 'none',
			'-ms-transition' : 'none'
		});

		setTimeout(function() {
			$('#slideshow_current').attr('id', 'temp_id');
			$('#slideshow_next').attr('id', 'slideshow_current');
			$('#temp_id').attr('id', 'slideshow_next');

			$('#slideshow_next').css({
				'display' : 'none'
			});

			$('#slideshow_current').css({
				'margin-left' : -250,
				'margin-top' : -250,
				'opacity' : 1,
				'-webkit-transform' : 'translate3d(0,0,0)',
				'-moz-transform' : 'translate3d(0,0,0)',
				'-o-transform' : 'translate3d(0,0,0)',
				'-ms-transform' : 'translate3d(0,0,0)'
			});
			setTimeout(function() {
				animatingBag = false;
				zoomBlocked = false;
			}, 40);
		

			ggl.fadeInBagInfo();
			
		}, 5);
	};
	return {
		getCurrentModel : function(){
			return currentModel;
		},
		preload : function(images, callback) {
			$('#scroller_middle, #story_column, #meta_column, #bags_column').css('display', 'block');
			var totalImages = images.length, imagesLoaded = 0;
			$('#big_loading').css('display', 'block').stop().animate({
				'opacity' : 0.9
			}, {
				duration : 300
			});
			if(totalImages == 0) {
				$('#big_loading').css('display', 'none');
				$('#meta_column').delay(300).animate({
					opacity : 0
				}, {
					duration : 100,
					complete : function() {
						$(this).css({
							'display' : 'none'
						});
						callback.call();
					}
				});
			} else {
				$('#meta_column').delay(300).animate({
					opacity : 0
				}, {
					duration : 100,
					complete : function() {
						$(this).css({
							'display' : 'none'
						});
					}
				});
				$('#loading_progress').html('0 of ' + totalImages + ' loaded');
				for(var i = 0; i < totalImages; i++) {
					var newImg = $('<img/>', {
						'src' : images[i]
					});
					if(newImg.get(0).complete) {
						imagesLoaded++;
						$('#loading_progress').html(imagesLoaded + ' of ' + totalImages + ' loaded');
						if(imagesLoaded >= totalImages) {
							$('#big_loading').delay(200).animate({
								'opacity' : 0
							}, {
								duration : 300,
								complete : function() {
									$(this).css('display', 'none');
									callback.call();
								}
							});

						}
					} else {
						newImg.load(function() {
							imagesLoaded++;

							$('#loading_progress').html(imagesLoaded + ' of ' + totalImages + ' loaded');
							if(imagesLoaded >= totalImages) {
								$('#big_loading').delay(200).animate({
									'opacity' : 0
								}, {
									duration : 300,
									complete : function() {
										$(this).css('display', 'none');
										callback.call();
									}
								});

							}
						});
					}
				}
			}
		},
		loadMoreStories : function() {
			if(!loadingMoreStories) {
				loadingMoreStories = true;
				$.ajax({
					url : 'http://' + document.domain + '?offset=' + $('.story').size() + '&length=3',
					dataType : "html",
					success : function(data) {

						var ajaxContent = $(data).find('#scroller_middle');

						var newStoriesSize = $(data).find('.story').size();
						if(newStoriesSize == 0) {
							moreStories = false;
						} else {
							ggl.resize();

							var imagesLoaded = 0;
							var totalImages = 0;
							var images = new Array();

							ajaxContent.find('.story').each(function(i) {
								var imgUrl = $(this).attr('data-src');
								imgUrl = imgUrl.replace(/type=custom&w=[\d]*/g, redaxoImgType);
								$(this).css({
									'background-image' : imgUrl
								});
								if(!Modernizr.touch) {
									$(this).css({
										top : 2000
									});
								}
								images.push(imgUrl);
								
								
								$(this).find('img').each(function(j){
									if(!Modernizr.touch){
										images.push($(this).attr('src'));
									}else{
										$(this).css('opacity',0);
									}
								});
								
								
							});
							$('#big_loading').css('display', 'block').stop().animate({
								'opacity' : 0.9
							}, {
								duration : 300
							});
							$('#loading_progress').html('Loading more posts...');
							totalImages = images.length;

							for(var i = 0; i < totalImages; i++) {
								
								var newImg = $('<img/>', {
									'src' : images[i]
								});
								if(newImg.get(0).complete) {
									imagesLoaded++;
									if(imagesLoaded >= totalImages) {
										ggl.loadMoreStoriesCallback(ajaxContent.html());
									}
								} else {
									newImg.load(function() {
										imagesLoaded++;
										if(imagesLoaded >= totalImages) {
											ggl.loadMoreStoriesCallback(ajaxContent.html());
										}
									});
								}

							}
						}
					}
				});
			}
		},
		loadMoreStoriesCallback : function(innerHTML) {
			$('#big_loading').delay(200).animate({
				'opacity' : 0
			}, {
				duration : 300,
				complete : function() {
					$(this).css('display', 'none');
					$('#scroller_middle').append(innerHTML.replace('###br###', '</br>'));
					
					if(Modernizr.touch){
						$('#scroller_middle img').each(function() {									
							$(this).load(function(){
								$(this).delay(100).animate({
									'opacity' : 1								
								},{
									duration:400
								});	
							});										
						});
					}									
					
					loadingMoreStories = false;
					ggl.resize();
					ggl.updateParallaxUrl();
					
					if(jQuery.browser.mobile && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 5_\d/i) && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 4_\d/i)) {
						//myScrollMiddle.refresh();
					}
					
					if($('#scroller_middle .story').size() == 3 && !Modernizr.touch) {						  

						$('.story:first').css({
							top : 0
						});
						$('.story:gt(0)').css({
							top : windowHeight
						});

						$(window).scrollTop(60);
						if($('html').hasClass('oldie')) {
							setTimeout(function() {
								$('.ie8 .article_bag, .ie8 .article_title').css('filter', '');
							}, 520);
						} else {
							$('body').css('opacity', 0).delay(200).animate({
								opacity : 1
							}, {
								duration : 400
							});
						}
					}
					
				}
			});
		},
		zoomLoaded : function() {
			return zoomLoaded;
		},
		loadZoom : function() {

			/* FADE OUT NAVI, HEADER ETC. */
			$('#header').animate({
				'margin-top' : -200,
				'opacity' : 0
			}, {
				duration : 400,
				easing : 'easeOutSine'
			});
			$('#previous_color, #previous_bag').animate({
				'left' : 0,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine'
			});
			$('#next_color, #next_bag').animate({
				'right' : 0,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine'
			});
			$('#bag_info').animate({
				'right' : -150,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine'
			});
			$('.go_from_bags_to_blog, .go_from_bags_to_story').animate({
				'margin-right' : -50,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine'
			});
			/* END OF FADE OUT NAVI, HEADER ETC. */

			var imgString = $('#slideshow_current img:first').attr('src');
			$('#line_zoom_img').html('<img src="' + imgString + '" alt="zoom_image">');
			$('#line_zoom_loading').css('display', 'block');

			var imgPos = $('#slideshow_current img:first').offset();
			zoomMLeft = imgPos.left;
			zoomMTop = imgPos.top;
			$('#line_zoom img').css({
				'top' : imgPos.top,
				'left' : imgPos.left
			});
			$('#slideshow_current').css('display', 'none');
			$('#line_zoom').css({
				'display' : 'block',
				'opacity' : 1
			});
			$('#line_zoom img').css({
				'-webkit-transition' : 'all 0.4s ease-out',
				'-moz-transition' : 'all 0.4s ease-out',
				'-o-transition' : 'all 0.4s ease-out'
			});

			$('#line_zoom').css({
				top : $('#bags_scroller').scrollTop()
			});

			var scaleFactor = $(window).width() / 500;

			setTimeout(function() {
				$('#line_zoom img').css({
					'-webkit-transform' : 'scale(' + scaleFactor + ') translateZ(0)',
					'-moz-transform' : 'scale(' + scaleFactor + ')',
					'-o-transform' : 'scale(' + scaleFactor + ')'
				});
			}, 5);
			setTimeout(function() {
			}, 600);
			var imgLink = $('#line_zoom img:first').attr('src').replace('slideshow', 'zoom');
			var newImg = $('<img/>', {
				'src' : imgLink,
				'width' : $(window).width()
			});
			if($(newImg).get(0).complete) {
				ggl.zoomImgLoadedCallback(imgLink, imgPos);
			} else {
				newImg.load(function() {
					ggl.zoomImgLoadedCallback(imgLink, imgPos);
				});
			}

		},
		zoomImgLoadedCallback : function(imgLink, imgPos) {
			$('#line_zoom_loading').css('display', 'none');
			setTimeout(function() {
				$('#bags_scroller').css('overflow-y', 'hidden');
				$('#line_zoom img').css({
					'-webkit-transition' : 'none',
					'-moz-transition' : 'none',
					'-o-transition' : 'none'
				});
				zoomLoaded = true;
				$('#line_zoom_img').html('<img id="zoom_bag" data-offsetX="0" data-offsetY="0" src="' + imgLink + '" width="100%" alt="bag_zoom">');
				$('#line_zoom img:first').css({
					'-webkit-transform' : 'scale(1) translateZ(0)',
					'-moz-transform' : 'scale(1)',
					'-o-transform' : 'scale(1)',
					'margin-left' : ($(window).width() - 500) / -2,
					'margin-top' : ($(window).width() - 500) / -2,
					'top' : imgPos.top,
					'left' : imgPos.left
				});
				$('.ie8 #line_zoom').css('filter', '');
				zoomTouchClass = new touchClass(document.getElementById('zoom_bag'), 'zoom_item');

			}, 20);
		},
		closeZoom : function() {
			zoomLoaded = false;
			var scaleFactor = 500 / $(window).width();
			$('#line_zoom img').css({
				'-webkit-transition' : 'all 0.4s ease-out',
				'-moz-transition' : 'all 0.4s ease-out',
				'-o-transition' : 'all 0.4s ease-out'
			});
			setTimeout(function() {
				$('#line_zoom img').css({
					'-webkit-transform' : 'scale(' + scaleFactor + ') translateZ(0)',
					'-moz-transform' : 'scale(' + scaleFactor + ')',
					'-o-transform' : 'scale(' + scaleFactor + ')',
					'margin-top' : ($(window).width() - 500) / -2
				});
			}, 5);
			setTimeout(function() {
				$('#slideshow_current').css('display', 'block');
				$('#line_zoom').css({
					'display' : 'none',
					'opacity' : 0
				});
				$('#line_zoom_img').empty();
				if($('html').hasClass('ie8')) {
					$('#header').css({
						'margin-top' : 0,
						'filter' : ''
					});
				} else {
					$('#header').animate({
						'margin-top' : 0,
						'opacity' : 1
					}, {
						duration : 400,
						easing : 'easeOutSine'
					});
				}
				$('#previous_color, #previous_bag').animate({
					'left' : 130,
					'opacity' : 1
				}, {
					duration : 200,
					easing : 'easeOutSine'
				});
				$('#next_color, #next_bag').animate({
					'right' : 130,
					'opacity' : 1
				}, {
					duration : 200,
					easing : 'easeOutSine'
				});
				$('#bag_info').animate({
					'right' : -74,
					'opacity' : 1
				}, {
					duration : 200,
					easing : 'easeOutSine'
				});
				$('.go_from_bags_to_blog, .go_from_bags_to_story').animate({
					'margin-right' : 0,
					'opacity' : 1
				}, {
					duration : 200,
					easing : 'easeOutSine'
				});
				$('#bags_scroller').css('overflow-y', 'scroll');
			}, 410);
		},
		openMeta : function(link) {

			$.ajax({
				url : link,
				dataType : "html",
				success : function(data) {

					ggl.resize();
					if(data.indexOf("spotted") != -1){
						var extendRedaxoImgType = redaxoImgType.replace(""+redaxoCurrentImgWidth, ""+(redaxoCurrentImgWidth+290));
					}else{
						var extendRedaxoImgType = redaxoImgType;
					}
					data = data.replace(/type=custom&w=[\d]*/g, extendRedaxoImgType);
					
					var ajaxContent = $(data).filter('#ajax_content');
					//data = data.replace(/type=custom&w=[\d]*/g, redaxoImgType);
					
					var currentTitle = $(data).find('#ajax_title').html().replace('&amp;', '&');
					document.title = currentTitle;

					var menuMarkup = $(data).filter('#main_menu').html();
					$('#main_menu').html(menuMarkup);

					$('.go_from_bags_to_blog, .go_from_story_to_blog').css({
						'display' : 'none',
						'opacity' : 0
					});

					$('#scroller_meta').html(ajaxContent.html());

					$('#scroller_meta').css('visibility', 'hidden');

					var metaImgs = new Array();

					$('#scroller_meta img').each(function(index) {
						metaImgs.push($(this).attr('src'));
						metaImgs.push($(this).attr('src'));
					});

					ggl.preload(metaImgs, function() {
						$('#scroller_meta').css('visibility', 'visible');
						$('html').css('overflow-y', 'hidden');

						$('#fake_scroller').css('display', 'none');
						//$('#header').css('width', $(window).width() - scrollbarWidth());
						$('#meta_column').stop().css({
							'display' : 'block',
							top : 0,
							opacity : 0
						});

						$('#scroller_meta .parallax_bg').each(function(index) {
							var thisHeight = $(this).width() / $(this).attr('data-ratio');
							$(this).css('height', Math.floor(thisHeight));
						});

						$('#scroller_meta').animate({
							'scrollTop' : 1
						}, {
							duration : 5
						});
						currentColumn = 'middle';
						ggl.slideOutStoryToBlogLink();
						ggl.slideOutStoryToBagsLink();
						ggl.slideOutBagsToBlogLink();
						ggl.slideOutLineToStoryLink();

						if(Modernizr.csstransforms3d && Modernizr.touch) {
							$('#columns_wrapper').removeClass('bags').removeClass('story');
						} else {
							$('#columns_wrapper').animate({
								'margin-left' : '-100%'
							}, {
								duration : 400,
								easing : 'easeOutSine'
							});
						}

						$('#meta_column').css('display', 'block').delay(100).animate({
							opacity : 1
						}, {
							duration : 400,
							complete : function() {
								$('#scroller_middle, #story_column, #bags_column').css('display', 'none');
								ggl.resetBags();
							}
						});

						ggl.resize();

						if($('#contact_form').length > 0) {
							$.getScript('js/contact.js', function(data, textStatus) {
								ggl_contact.init();
							});
						}

						if($('#credit_leistungen').length > 0) {
							$.getScript('js/creditcard.js', function(data, textStatus) {
								ggl_credit.init();
							});
						}

					});
				}
			});
		},
		loadStoriesMarkup : function() {
			$.ajax({
				url : showStoriesLink,
				dataType : "html",
				success : function(data) {
					var ajaxContent = $(data).filter('#ajax_content');
					theStories_color = ajaxContent.find('#meta_info').attr('data-gradientStop');
					theStories_bg = ajaxContent.find('#meta_info').attr('data-bg');
					$('#the_stories_overlay').html(ajaxContent);

					var currentTitle = $(data).find('#ajax_title').html().replace('&amp;', '&');
					document.title = currentTitle;
					var menuMarkup = $(data).filter('#main_menu').html();
					$('#main_menu').html(menuMarkup);
					$('.rex-current').css({
						color : theStories_color
					});

					ggl.resize();
					ggl.loadStories();
				}
			});
		},
		loadStories : function() {

			$('#fake_scroller').css('display', 'none');
			$('html').css('overflow-y', 'hidden');

			var submenuHeight = $('#main_menu_list .nav_1 .nav_1 ul').height();
			if($(window).width() > 600) {
				$('#the_stories_heading ').css('margin-top', 142 + submenuHeight);
				$('.go_from_story_to_blog').css('top', 197 + submenuHeight);
			} else {
				$('#the_stories_heading ').css('margin-top', 100 + submenuHeight);
				$('.go_from_story_to_blog').css('top', 157 + submenuHeight);
			}

			ggl.slideOutBagsToBlogLink();
			ggl.slideOutLineToStoryLink();
			setTimeout(function() {
				ggl.slideInStoryToBlogLink();
				ggl.slideOutStoryToBagsLink();
			}, 400);

			$('#the_stories_gradient_wrapper,#the_stories_bg,#the_stories').css('display', 'block');

			$('.storie_thumb img').css({
				'opacity' : 0,
				'margin-top' : 20
			});

			if(currentColumn == 'right') {
				ggl.updateColors(hightLightColor);
				$('#the_stories_bg, #the_stories_gradient_wrapper').animate({
					'opacity' : 1
				}, {
					duration : 300
				});
				$('#the_stories').delay(400).animate({
					'opacity' : 1
				}, {
					duration : 500,
					complete : function() {
						var tmpDelay = 0;
						$('.storie_thumb img').each(function() {
							$(this).delay(tmpDelay).animate({
								'opacity' : 1,
								'margin-top' : 0
							});
							tmpDelay += 100;
						});
					}
				});

			} else {
				currentColumn = 'right';
				hightLightColor = theStories_color;
				$('#the_stories_bg').css('background-image', 'url(' + theStories_bg + ')');
				var R = hexToR(hightLightColor);
				var G = hexToG(hightLightColor);
				var B = hexToB(hightLightColor);

				$('#the_stories_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#the_stories_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#the_stories_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#the_stories_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
				$('#ie_bags_gradient_2').attr('src', 'en/image?type=gradient&clr=' + hightLightColor.replace('#', ''));

				ggl.updateColors(hightLightColor);

				var theStoriesbg = new Array();
				theStoriesbg.push(theStories_bg);
				ggl.preload(theStoriesbg, function() {
					if(Modernizr.csstransforms3d && Modernizr.touch) {
						$('#columns_wrapper').removeClass('bags').addClass('story');
					} else {
						$('#columns_wrapper').animate({
							'margin-left' : '-200%'
						}, {
							duration : 400,
							easing : 'easeOutSine'
						});
					}
					$('#the_stories_bg, #the_stories_gradient_wrapper, #the_stories').css({
						'opacity' : 1,
						'display' : 'block'
					});

					$('.storie_thumb img').css({
						'opacity' : 1,
						'margin-top' : 0
					});

				});
			}
		},
		loadCollectionMarkup : function() {
			$.ajax({
				url : showCollectionLink,
				dataType : "html",
				success : function(data) {
					var ajaxContent = $(data).filter('#ajax_content');
					theBags_color = ajaxContent.find('#meta_info').attr('data-gradientStop');
					theBags_bg = ajaxContent.find('#meta_info').attr('data-bg');

					$('#the_bags_overlay').html(ajaxContent);

					var currentTitle = ajaxContent.find('#ajax_title').html().replace('&amp;', '&');
					document.title = currentTitle;

					var menuMarkup = $(data).filter('#main_menu').html();
					$('#main_menu').html(menuMarkup);
					$('.rex-current').css({
						color : theBags_color
					});

					ggl.loadCollection();
				}
			});
		},
		loadCollection : function() {
			ggl.slideOutLineToStoryLink();
			ggl.slideOutStoryToBlogLink();
			ggl.slideOutStoryToBagsLink();

			var submenuHeight = $('#main_menu_list .nav_1 .nav_1 ul').height();
			
			if($(window).width() > 600) {
				$('.no-touch #the_bags_heading ').css({
					'top' : 142 + submenuHeight,
					'margin-top' : 0
				});
				$('.go_from_bags_to_blog').css('top', 197 + submenuHeight);
			} else {
				$('.touch #the_bags_heading ').css({
					'top' : 0,
					'margin-top' : -150 + submenuHeight
				});
				$('.go_from_bags_to_blog').css('top', 160 + submenuHeight);
			}

			

			

			$('#the_bags').css('display', 'block');
			$('#fake_scroller').css('display', 'none');
			var ie8 = $('html').hasClass('ie8');

			$('.bag_thumb_gradient').each(function() {
				var gradientStop = $(this).attr('data-gradient');
				var R = hexToR(gradientStop);
				var G = hexToG(gradientStop);
				var B = hexToB(gradientStop);
				if(!Modernizr.cssgradients) {
					$(this).html('<img class="ie_thumb_gradient" width="100%" height="100%" src="en/image?type=gradient&clr=' + gradientStop.replace('#', '') + ' alt="gradient">');
				}
				$(this).css('background-image', '-moz-linear-gradient(rgba(0,0,0, 0.5) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$(this).css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0, 0.5) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$(this).css('background-image', '-o-linear-gradient(top, rgba(0,0,0, 0.5) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$(this).css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.5)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');

			});
			$('.bag_thumb img').stop().css({
				'opacity' : 0,
				'margin-top' : -60
			});
			if(currentColumn == 'left') {
				ggl.updateColors(hightLightColor);

				$('#bags_column').animate({
					'scrollTop' : 0
				}, {
					duration : 300
				});
				if($('html').hasClass('ie8')) {
					$('#line_slideshow, #line_list, #line_show_all, #where_to_buy').css('display', 'none');
				}
				$('#line_slideshow').delay(300).animate({
					'opacity' : 0,
					'margin-top' : -50
				}, {
					'duration' : 300,
					'easing' : 'easeInSine',
					'complete' : function() {
						$('#line_list').empty();
						$('#line_slideshow, #where_to_buy').css('display', 'none');
						if($('html').hasClass('ie8')) {
							setTimeout(function() {
								$('#the_bags').css({
									'display' : 'block',
									'filter' : ''
								});
							}, 10);
							var durationAnim = 0;
						} else {
							var durationAnim = 400;
						}
						$('#the_bags').animate({
							'opacity' : 1
						}, {
							duration : durationAnim,
							complete : function() {
								ggl.resize();
								var tmpDelay = 200;
								$('.bag_thumb img').each(function() {
									if(ie8) {
										$(this).css({
											'filter' : '',
											'margin-top' : -80
										});
									} else {
										$(this).delay(tmpDelay).animate({
											'opacity' : 1,
											'margin-top' : -80
										});
										tmpDelay += 100;
									}
								});
								if($('html').hasClass('ie8')) {
									$('#the_bags').css({
										'display' : 'block',
										'filter' : ''
									});
								}
							}
						});
					}
				});
				$('#line_list, #line_show_all, #where_to_buy').delay(300).animate({
					'opacity' : 0,
					'margin-top' : -50
				}, {
					'duration' : 300,
					'easing' : 'easeInSine',
					'complete' : function() {

					}
				});
			} else {
				currentColumn = 'left';
				hightLightColor = theBags_color;
				var R = hexToR(theBags_color);
				var G = hexToG(theBags_color);
				var B = hexToB(theBags_color);

				$('#bags_column').css('background-image', 'url(' + theBags_bg + ')');
				$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
				$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + hightLightColor.replace('#', ''));

				ggl.updateColors(hightLightColor);

				var theBagsbg = new Array();
				theBagsbg.push(theBags_bg);
				ggl.preload(theBagsbg, function() {
					ggl.slideInBagsToBlogLink();
					ggl.goToLeft();
					ggl.resize();
					$('#bags_column').animate({
						'scrollTop' : 0
					}, {
						duration : 0
					});

					$('#line_slideshow, #line_list, #line_show_all').css({
						'opacity' : 0,
						'margin-top' : -50
					});
					if($('html').hasClass('ie8')) {
						setTimeout(function() {
							$('#the_bags').css({
								'display' : 'block',
								'filter' : ''
							});
						}, 10);
						var durationAnim = 0;
					} else {
						var durationAnim = 400;
					}
					$('#the_bags').css('opacity', 0).delay(600).animate({
						'opacity' : 1
					}, {
						duration : durationAnim,
						complete : function() {
							var tmpDelay = 200;
							$('.bag_thumb img').each(function() {
								if(ie8) {
									$(this).css({
										'filter' : '',
										'margin-top' : -80
									});
								} else {
									$(this).delay(tmpDelay).animate({
										'opacity' : 1,
										'margin-top' : -80
									});
									tmpDelay += 100;
								}
							});
							if($('html').hasClass('ie8')) {
								$('#the_bags').css({
									'display' : 'block',
									'filter' : ''
								});
							}
						}
					});
				});
			}
			currentColumn = 'left';

		},
		setCurrentColumn : function(column) {
			currentColumn = column;
		},
		loadStory : function(link) {

			$.ajax({
				url : link,
				dataType : "html",
				success : function(data) {
					currentColumn = 'right';
					if($('.go_from_story_to_blog ').css('top') == '200px') {
						$('.go_from_story_to_blog ').css('top', 142 + $('#main_menu_list .nav_1 .nav_1 ul').height());
					}
					ggl.resize();
					data = data.replace(/type=customasset&w=[\d]*/g, redaxoImgType.replace('custom', 'customasset')).replace(/type=custom&w=[\d]*/g, redaxoImgType);

					var ajaxContent = $(data).filter('#ajax_content');

					var meta = ajaxContent.find('#meta_info');
					var currentTitle = ajaxContent.find('#ajax_title').html().replace('&amp;', '&');
					document.title = currentTitle;

					var bg = $(meta).attr('data-bg');
					var fallbackBg = $(meta).attr('data-fallbackbackground');
					var color = $(meta).attr('data-maincolor');
					hightLightColor = color;

					var lineLink = $(meta).attr('data-line');
					if(lineLink != '') {
						$('.go_from_story_to_bags .line_link').attr('href', lineLink).attr('data-xml', lineLink);
					} else {
						$('.go_from_story_to_bags .line_link').attr('href', '').attr('data-xml', '');
					}

					var menuMarkup = $(data).filter('#main_menu').html();
					$('#main_menu').html(menuMarkup);
					$('.rex-current').css({
						color : hightLightColor
					});

					var storyWrapperHeight = 0;
					var storyImages = new Array();
					storyImages.push(bg);

					ajaxContent.find('img.parallax_item').each(function() {
						storyImages.push($(this).attr('src'));
					});

					ajaxContent.find('.parallax_bg').each(function() {
						var imgUrl = 'url(' + $(this).attr('data-src') + ')';
						imgUrl = imgUrl.replace(/type=custom&w=[\d]*/g, redaxoImgType);
						$(this).css('background-image', imgUrl);
						var thisHeight = redaxoCurrentImgWidth / $(this).attr('data-ratio') * 0.8;
						$(this).css('height', Math.floor(thisHeight));
						storyWrapperHeight += Math.floor(thisHeight);
						storyImages.push(imgUrl.replace(/\"/g, '').replace('url(', '').replace(')', '').replace(/\'/g, ''));
					});
					$('#fake_scroller').css('height', storyWrapperHeight);

					$('#scroller_right').html(ajaxContent.html());

					//ggl.updateParallaxUrl();

					if(!Modernizr.touch) {
						ggl.updateStoryOnScroll();
					}

					$('#scroller_right').delay(200).animate({
						scrollTop : 5
					}, {
						duration : 5
					});

					$('#scroller_right .parallax_item').each(function(index) {
						if($(this).attr('data-id')) {
							$('#' + $(this).attr('data-id')).append($(this));
						}
					});

					$(window).scrollTop(0);

					if(fallbackBg != "/files/") {
						storyImages.push(fallbackBg);
					}

					ggl.preload(storyImages, function() {
						ggl.slideOutBagsToBlogLink();
						ggl.slideOutLineToStoryLink();
						ggl.slideInStoryToBlogLink();
						ggl.slideInStoryToBagsLink();

						$('#fake_scroller').css('display', 'block');
						$('html').css('overflow-y', 'scroll');
						$('#the_stories_gradient_wrapper, #the_stories_bg').animate({
							'opacity' : 0
						}, {
							duration : 400,
							complete : function() {
								$('#the_stories_gradient_wrapper, #the_stories_bg').css('display', 'none');
							}
						});
						$('#the_stories').animate({
							'opacity' : 0
						}, {
							duration : 400,
							complete : function() {
								$(this).css('display', 'none');
								$('#the_stories_bg').css('background-image', 'url(' + bg + ')');
								var R = hexToR(hightLightColor);
								var G = hexToG(hightLightColor);
								var B = hexToB(hightLightColor);

								$('#the_stories_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
								$('#the_stories_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
								$('#the_stories_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
								$('#the_stories_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');

							}
						});

						if(Modernizr.csstransforms3d && Modernizr.touch) {
							$('#columns_wrapper').removeClass('bags').addClass('story');
						} else {
							$('#columns_wrapper').animate({
								'margin-left' : '-200%'
							}, {
								duration : 400,
								easing : 'easeOutSine'
							});
						}

						$('.go_from_story_to_blog ').css('top', 150 + $('#main_menu_list .nav_1 .nav_2 ul').height());

						if(fallbackBg != "/files/") {
							$('#scroller_right').css('background', 'url(\'' + fallbackBg + '\') repeat scroll 0 0 #000000');
						}

						ggl.updateColors(hightLightColor);

					});
				}
			});

		},
		loadLine : function(xml_path, showSlideshow) {
			
			
			$('#scroller_meta').empty();
			$('#bags_column').animate({
				'scrollTop' : 0
			}, {
				duration : 0
			});
			$('#big_loading').css({
				'display' : 'block',
				opacity : 0.9
			});
			$('#loading_progress').html('Loading Line...');
			var xml = loadXML(xml_path);
			lineName = $(xml).find('label').text();
			linePathPrefix = $(xml).find('line').attr('imgprefix');
			lineBg = $(xml).find('line').attr('bg');
			hightLightColor = $(xml).find('line').attr('bagcolor');
			$('.slideshow_bag_line').html(lineName);

			var storyLink = $(xml).find('line').attr('story-url');
			if(storyLink != '') {
				$('.go_from_bags_to_story .story_link').attr('href', storyLink);
			} else {
				$('.go_from_bags_to_story .story_link').attr('href', '');
			}
			lineModels.length = lineColors.length = currentColor = currentModel = 0;

			$.ajax({
				url : xml_path.replace('?xml=true', ''),
				dataType : "html",
				success : function(data) {
					var currentTitle = $(data).find('#ajax_title').html().replace('&amp;', '&');
					document.title = currentTitle;

					var menuMarkup = $(data).filter('#main_menu').html();
					$('#main_menu').html(menuMarkup);
					$('.rex-current').css({
						color : hightLightColor
					});
				}
			});

			$(xml).find('color').each(function() {
				lineColors.push({
					id : $(this).attr('id'),
					name : $(this).text(),
					color : $(this).attr('hex')
				});
			});
			$(xml).find('model').each(function() {
				lineModels.push({
					name : $(this).text(),
					imglabel : $(this).attr('imglabel'),
					dimensions : $(this).attr('dimensions'),
					exclude : $(this).attr('exclude'),
					offset : $(this).attr('offset'),
					ar : $(this).attr('ar'),
					id : $(this).attr('id')
				});

			});
			if(showSlideshow) {
				
				var lineBgArr = new Array();
				lineBgArr.push(lineBg);
				$('#bags_column').css('background-image', 'url(' + lineBg + ')');
				ggl.updateColors(hightLightColor);
				var cHash = window.location.href;
				var urlModel = unescape(cHash.replace(/[\s\S]*collection12012\/[^\/]*\/([^\/]*)[\d\D]*/g, '$1'));
				var urlColor = cHash.replace(/[\s\S]*collection12012\/[^\/]*\/[^\/]*\/([^\/]*)[\d\D]*/g, '$1');
				
				for(var i = 0, len = lineModels.length; i < len; i++) {
					var urlModelTmp = lineModels[i].name.trim().replace("!","").replace(":","").replace("'","").replace("´","").replace("&","und");
					urlModelTmp = urlModelTmp.toLowerCase().trim().replace(/[\s]/g, '-');
					
					if(urlModel == urlModelTmp) {
						currentModel = i;
					}
				}
				
				for(var i = 0, len = lineColors.length; i < len; i++) {
					var urlColorTmp = lineColors[i].name.replace(":","");
					urlColorTmp = urlColorTmp.toLowerCase().trim().replace(/[\s]/g, '-').replace("´","");
					if(urlColor == urlColorTmp) {
						currentColor = i;
					}
				}
				
				document.title = lineModels[currentModel].name + ' in ' + lineColors[currentColor].name + document.title;
				ggl.showBag(currentModel, currentColor);
				
				ggl.preload(lineBgArr, function() {
					ggl.goToLeft();
					ggl.slideInBagsToBlogLink();
					ggl.slideInLineToStoryLink();
				});
				
			} else {
				ggl.showLine();
			}

		},
		showLine : function() {

			var lineBgArr = new Array();
			lineBgArr.push(lineBg);
			ggl.preload(lineBgArr, function() {
				var wrapper = $('#line_list');
				wrapper.empty();
				ggl.slideOutStoryToBlogLink();
				ggl.slideOutStoryToBagsLink();

				var R = hexToR(hightLightColor);
				var G = hexToG(hightLightColor);
				var B = hexToB(hightLightColor);
				$('#bags_column').css('background-image', 'url(' + lineBg + ')');
				$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
				$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
				$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + hightLightColor.replace('#', ''));

				ggl.goToLeft(function() {
					ggl.slideInBagsToBlogLink();
					ggl.slideInLineToStoryLink();
					if($('.go_from_bags_to_story .story_link:first').attr('href') == '') {
						$('.go_from_bags_to_story').css('display', 'none');
					}
					for(var i = 0, len = lineModels.length; i < len; i++) {
						var modelName = lineModels[i].name;
						var imgName = lineModels[i].imglabel;
						var colorName = lineColors[i % lineColors.length].name.toLowerCase();
						var colorId = lineColors[i % lineColors.length].id;
						var dataColor = i % lineColors.length;
						wrapper.append('<div class="line_bag" data-model="' + i + '" data-color="' + dataColor + '">' + '<a href="javascript:void(0);" class="show_bag">' + '<img style="opacity:0;" src="en/image?type=thumb&trim=true&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">' + '<div class="thumbLoading"></div>' + '</a>' + '<div class="line_bag_info">' + '<span class="line_bag_line lineBgColor">' + lineName + '</span>' + '<span class="line_bag_model">' + modelName + '</span>' + '<span class="line_bag_color">Color: ' + colorName + '</span>' + '</div>' + '</div>');
					}					
				
					ggl.updateColors(hightLightColor);
					$('.line_bag img').each(function() {
						$(this).load(function() {
							$(this).parent().find('.thumbLoading').remove();
							if($('html').hasClass('ie8')) {
								$(this).css('filter', '');
							} else {
								$(this).animate({
									'opacity' : 1
								});
							}
						});
					});
					$('.line_bag, #line_list').css('filter', '');
					
					if(jQuery.browser.mobile && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 5_\d/i) && !navigator.userAgent.match(/(iPhone);.*CPU.*OS 4_\d/i)) {
						//myScrollLeft.refresh();
					}
				});
			});
		},
		slideInStoryToBagsLink : function() {
			$('.go_from_story_to_bags').css({
				'display' : 'block',
				'opacity' : 0,
				'margin-left' : -30
			}).delay(600).animate({
				'margin-left' : 0,
				'opacity' : 1
			}, {
				duration : 400,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('filter', '');
				}
			});
		},
		slideOutStoryToBagsLink : function() {
			$('.go_from_story_to_bags').stop().animate({
				'opacity' : 0,
				'margin-left' : -200
			}, {
				'duration' : 100,
				'complete' : function() {
					$(this).css('display', 'none');
				}
			});
		},
		slideInStoryToBlogLink : function() {
			$('.go_from_story_to_blog').css({
				'display' : 'block',
				opacity : 0,
				'margin-left' : -30
			}).delay(600).animate({
				'margin-left' : 0,
				'opacity' : 1
			}, {
				duration : 400,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('filter', '');
				}
			});
		},
		slideOutStoryToBlogLink : function() {
			$('.go_from_story_to_blog').stop().animate({
				'opacity' : 0,
				'margin-left' : -200
			}, {
				'duration' : 100,
				'complete' : function() {
					$(this).css('display', 'none');
				}
			});
		},
		slideInBagsToBlogLink : function() {
			$('.go_from_bags_to_blog').css({
				display : 'block',
				'margin-right' : -20,
				opacity : 0
			}).delay(600).animate({
				opacity : 1,
				'margin-right' : 0
			}, {
				duration : 400,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('filter', '');
				}
			});
		},
		slideOutBagsToBlogLink : function() {
			$('.go_from_bags_to_blog').animate({
				'margin-right' : -50,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('display', 'none');
				}
			});
		},
		slideInLineToStoryLink : function() {
			$('.go_from_bags_to_story').css({
				'display' : 'block',
				'margin-right' : -20,
				'opacity' : 0
			}).delay(600).animate({
				'margin-right' : 0,
				'opacity' : 1
			}, {
				duration : 400,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('filter', '');
				}
			});
		},
		slideOutLineToStoryLink : function() {
			$('.go_from_bags_to_story').animate({
				'margin-right' : -50,
				'opacity' : 0
			}, {
				duration : 200,
				easing : 'easeOutSine',
				complete : function() {
					$(this).css('display', 'none');
				}
			});
		},
		updateColors : function(newColor) {
			$('.lineBgColor').css({
				'background-color' : newColor
			});
			$('.menulink_font').css({
				color : newColor + '!important'
			});

		},
		closeShowAll : function(type, model, color) {
			var imgName = lineModels[model].imglabel;
			var colorId = lineColors[color].id;
			currentColor = color;
			currentModel = model;

			ggl.slideInBagsToBlogLink();
			if($('.go_from_bags_to_story .story_link').attr('href') != '') {
				ggl.slideInLineToStoryLink();
			}

			$('#slideshow_current').html('<img src="en/image?type=slideshow&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">');
			$('#bags_column').animate({
				'scrollTop' : 0
			}, {
				duration : 300,
				easing : 'easeOutSine'
			});

			var suffixId = '';
			if(type == 'wtb') {
				suffixId = 'where_to_buy';
			} else {
				suffixId = 'line_show_all';
			}
			if($('html').hasClass('ie8')) {
				$('#' + suffixId).css('display', 'none');
			}
			$('#' + suffixId).delay(300).animate({
				'opacity' : 0,
				'margin-top' : 50
			}, {
				'duration' : 300,
				'easing' : 'easeInSine',
				'complete' : function() {
					$(this).css('display', 'none');
					$('#line_slideshow').css({
						'display' : 'block'
					}).animate({
						'opacity' : 1,
						'margin-top' : 0
					}, {
						'duration' : 300,
						complete : function() {
							$('.ie8 #line_slideshow').css('filter', '');
						}
					});
					var newColor = lineColors[currentColor].color;
					var R = hexToR(newColor);
					var G = hexToG(newColor);
					var B = hexToB(newColor);
					//$('#bags_gradient_end').css('background', newColor);
					$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 80%)');
					$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
					$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
					$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
					$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + newColor.replace('#', ''));
				}
			});

		},
		resetBags : function() {
			$('#the_bags').css({
				display : 'none',
				opacity : 0
			});
			$('#line_slideshow').css({
				'opacity' : 0,
				'display' : 'none',
				'margin' : '0 0 0 -405px'
			});
			$('#line_show_all, #where_to_buy').css({
				'opacity' : 0,
				'display' : 'none',
				'margin' : '0'
			});
			$('#line_list').css({
				'opacity' : 1,
				'display' : 'block',
				'margin' : '220px 160px 0'
			}).empty();

		},
		showAll : function(type) {
			var wrapper = $('#line_show_all_overlay');

			wrapper.empty();

			ggl.slideOutBagsToBlogLink();
			ggl.slideOutLineToStoryLink();

			if(type == "models") {
				$('#line_show_all_heading').html('ALL MODELS');
				var colorId = lineColors[currentColor].id;
				var colorName = lineColors[currentColor].name.toLowerCase();
				for(var i = 0, len = lineModels.length; i < len; i++) {
					var modelName = lineModels[i].name;
					var imgName = lineModels[i].imglabel;

					wrapper.append('<div class="line_bag" data-type="model" data-model="' + i + '" data-color="' + currentColor + '">' + '<a href="javascript:void(0);" class="close_show_all"><div class="thumbLoading"></div><img src="en/image?type=thumb&trim=true&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png"></a>' + '<div class="line_bag_info">' + '<span class="line_bag_line lineBgColor">' + lineName + '</span>' + '<span class="line_bag_model">' + modelName + '</span>' + '<span class="line_bag_color">Color: ' + colorName + '</span>' + '</div>' + '</div>');
				}
			} else if(type == "colors") {
				$('#line_show_all_heading').html('ALL COLORS');
				var modelName = lineModels[currentModel].name;
				var imgName = lineModels[currentModel].imglabel;

				for(var i = 0, len = lineColors.length; i < len; i++) {
					var colorId = lineColors[i].id;
					var colorName = lineColors[i].name.toLowerCase();

					wrapper.append('<div class="line_bag" data-type="color" data-model="' + currentModel + '" data-color="' + i + '">' + '<a href="javascript:void(0);" class="close_show_all"><div class="thumbLoading"></div><img src="en/image?type=thumb&trim=true&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png"></a>' + '<div class="line_bag_info">' + '<span class="line_bag_line lineBgColor">' + lineName + '</span>' + '<span class="line_bag_model">' + modelName + '</span>' + '<span class="line_bag_color">Color: ' + colorName + '</span>' + '</div>' + '</div>');
				}
			}

			var ie8 = $('html').hasClass('ie8');

			$('#line_show_all_overlay img').each(function() {
				$(this).load(function() {
					$(this).parent().find('.thumbLoading').remove();
					if(ie8) {
						$(this).css({
							'filter' : ''
						});
					} else {
						$(this).animate({
							'opacity' : 1
						});
					}
				});
			});
			ggl.updateColors(hightLightColor);
			if($('html').hasClass('ie8')) {
				$('#line_slideshow').css('display', 'none');
			}
			$('#line_slideshow').delay(100).animate({
				'opacity' : 0,
				'margin-top' : -50
			}, {
				'duration' : 300,
				'easing' : 'easeInSine',
				'complete' : function() {
					$(this).css('display', 'none');
					$('#bags_column').animate({
						'scrollTop' : 0
					}, {
						duration : 100
					});
					if($('html').hasClass('ie8')) {
						$('#line_show_all').css({
							'display' : 'block',
							'margin-top' : 0
						});
						$('.ie8 #line_show_all').css('filter', '');
					} else {
						$('#line_show_all').css({
							'display' : 'block',
							'margin-top' : 70
						}).delay(100).animate({
							'opacity' : 1,
							'margin-top' : 0
						}, {
							'duration' : 400,
							'easing' : 'easeOutSine'
						});
					}

				}
			});
		},
		showWhereToBuy : function() {
			ggl.slideOutBagsToBlogLink();
			ggl.slideOutLineToStoryLink();

			var WTBID = lineModels[currentModel].id;

			//ERASE THIS
			//storefinder.setFilter('GV112SOF%20311');
			//storefinder.getWTBCountries('GV112SOF%20311');
			//

			storefinder.setFilter(WTBID + '%20' + lineColors[currentColor].id);
			storefinder.getWTBCountries(WTBID + '%20' + lineColors[currentColor].id);

			$('.wtb_bag').html(lineModels[currentModel].name);
			$('.wtb_color').html(lineColors[currentColor].name);

			$('#storefinder_select_country').css({
				'display' : 'block',
				opacity : 1
			});
			$('#storefinder_search').val($('#storefinder_search').attr('data-placeholder'));

			$('#where_to_buy_heading').html('Where to buy <span class="wtb_model" style="color: ' + hightLightColor + '">' + lineModels[currentModel].name + '</span> in color<span class="wtb_color" style="color: ' + hightLightColor + '">' + lineColors[currentColor].name + '</span>');

			$('#line_slideshow').delay(100).animate({
				'opacity' : 0,
				'margin-top' : -50
			}, {
				'duration' : 300,
				'easing' : 'easeInSine',
				'complete' : function() {
					$(this).css('display', 'none');
					$('#bags_column').animate({
						'scrollTop' : 0
					}, {
						duration : 100
					});
					if($('html').hasClass('ie8')) {
						$('#where_to_buy').css({
							'filter' : '',
							'display' : 'block'
						});
					} else {
						$('#where_to_buy').css({
							'display' : 'block',
							'margin-top' : 70
						}).delay(100).animate({
							'opacity' : 1,
							'margin-top' : 0
						}, {
							'duration' : 400,
							'easing' : 'easeOutSine'
						});
					}

				}
			});
		},
		switchBag : function(model, color) {
			currentModel = model;
			currentColor = color;
			
			var reflectionOffset = -93;
			var imgName = lineModels[currentModel].imglabel;
			var colorId = lineColors[currentColor].id;
			$('#slideshow_current').empty().append('<img src="en/image?type=slideshow&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png" alt="slide">').append('<img style="margin-top:' + reflectionOffset + 'px" src="en/image?type=reflection&amp;img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">');
			$('.slideshow_bag_model').html(lineModels[currentModel].name + ' <a href="javascript:void(0);" class="show_all_models lineBgColor">all models</a>');
			$('.slideshow_bag_color').html(lineColors[currentColor].name + ' <a href="javascript:void(0);" class="show_all_colors lineBgColor">all colors</a>');
			$('.slideshow_bag_dimensions').html(lineModels[currentModel].dimensions);
			$('.slideshow_bag_ar').empty();
			if(lineModels[currentModel].ar) {
				$('.slideshow_bag_ar').html('<a href="javascript:void(0);">TRY IT ON</a>');
			}
			var newColor = lineColors[currentColor].color;
			var R = hexToR(newColor);
			var G = hexToG(newColor);
			var B = hexToB(newColor);
			//$('#bags_gradient_end').css('background', newColor);
			$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 80%)');
			$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
			$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
			$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
			$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + newColor.replace('#', ''));
			ggl.updateColors(hightLightColor);
		},
		showBag : function(model, color) {
			currentModel = model;
			currentColor = color;
			var imgName = lineModels[currentModel].imglabel;
			var colorId = lineColors[currentColor].id;
			var scrollTo = 700 - $(window).height();

			var currentLine = document.location.href;
			currentLine = currentLine.replace(/([\s\S]*collection12012\/[^\/]*)[\s\S]*/g, '$1');

			var urlModelSuffix = lineModels[currentModel].name;
			urlModelSuffix = urlModelSuffix.toLowerCase().trim().replace(/[\s]/g, '-').trim().replace("!","").replace(":","").replace("'","").replace("´","").replace("&","und");
			var urlColorSuffix = lineColors[currentColor].name;
			urlColorSuffix = urlColorSuffix.toLowerCase().trim().replace(/[\s]/g, '-').replace(/[!|:]/g,"").replace("´","");
			currentLine += '/' + urlModelSuffix + '/' + urlColorSuffix;
			document.location.href = currentLine;
			
			if(lineModels[currentModel].offset == 'none'){				
				var opacitySuffix = "display:none;";		
			}else{			
				var opacitySuffix = "";	
				var reflectionOffset = -93;				
			}		
			
			if(lineModels[currentModel].offset != '') {
				//reflectionOffset+= lineModels[currentModel].offset;
			}
			$('#slideshow_current').html('<img src="en/image?type=slideshow&amp;img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">');
			$('#slideshow_current').append('<img style="'+opacitySuffix+'margin-top:' + reflectionOffset + 'px" src="en/image?type=reflection&amp;img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">');
			$('.slideshow_bag_model').html(lineModels[currentModel].name + ' <a href="javascript:void(0);" class="show_all_models lineBgColor">all models</a>');
			$('.slideshow_bag_color').html(lineColors[currentColor].name + ' <a href="javascript:void(0);" class="show_all_colors lineBgColor">all colors</a>');
			$('.slideshow_bag_dimensions').html(lineModels[currentModel].dimensions);
			if(lineModels[currentModel].ar) {
				$('.slideshow_bag_ar').html('<a href="javascript:void(0);">TRY IT ON</a>');
				$('.slideshow_bag_ar').click(function() {
					var left = (screen.width - 920 ) * .5;
					var top = (screen.height - 640 ) * .5;
					var tryiton = window.open("files/ar/?p=" + currentLine.replace(/http[s]?:\/\/[^\.]*\.[^\.]*\.[^\/]*\/#!/, ""), "tryiton", 'width=920, height=640, top=' + top + ', left=' + left, true);
					if(tryiton) {
						tryiton.focus();
					} else {
						var timer = window.setTimeout(function() {
							if(tryiton)
								tryiton.focus();
						}, 100);
					}
				});
			} else {
				$('.slideshow_bag_ar').empty();
			}

			var slideshowImgs = new Array();
			slideshowImgs.push('en/image?type=slideshow&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png');
			slideshowImgs.push('en/image?type=reflection&img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png');
			ggl.preload(slideshowImgs, function() {
				ggl.updateColors(hightLightColor);
				if($('html').hasClass('ie8')) {
					$('#line_list').css('display', 'none');
				}
				$('#line_list').animate({
					'opacity' : 0,
					'margin-top' : -50
				}, {
					'duration' : 300,
					'easing' : 'easeInSine',
					'complete' : function() {
						if(scrollTo > 0) {
							$('#bags_column').animate({
								'scrollTop' : scrollTo
							}, {
								duration : 200
							});
						}

						var newColor = lineColors[currentColor].color;
						var R = hexToR(newColor);
						var G = hexToG(newColor);
						var B = hexToB(newColor);
						//$('#bags_gradient_end').css('background', newColor);
						$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 80%)');
						$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
						$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
						$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
						$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + newColor.replace('#', ''));
						$(this).css('display', 'none');
						$('#line_slideshow').css({
							'display' : 'block',
							'margin-top' : 50
						}).animate({
							'opacity' : 1,
							'margin-top' : 0
						}, {
							'duration' : 300,
							complete : function() {
								$('.ie8 #line_slideshow').css('filter', '');
								document.title = lineModels[currentModel].name + ' in ' + lineColors[currentColor].name + document.title.replace(/[\s\S]*(\-[\s\S]+\-[\s]Bags[\s\S]+)/g, ' $1');

							}
						});

					}
				});
			});
		},
		changeBag : function(direction) {
			zoomBlocked = true;
			if(direction == 'nextBag') {
				currentModel = (currentModel * 1 + 1) % lineModels.length;
			} else if(direction == 'previousBag') {
				currentModel = (currentModel * 1 - 1 + lineModels.length) % lineModels.length;
			} else if(direction == 'nextColor') {
				currentColor = (currentColor * 1 + 1) % lineColors.length;
			} else if(direction == 'previousColor') {
				currentColor = (currentColor * 1 - 1 + lineColors.length) % lineColors.length;
			}

			var imgName = lineModels[currentModel].imglabel;
			var colorId = lineColors[currentColor].id;
			
			var currentLine = document.location.href;
			currentLine = currentLine.replace(/([\s\S]*collection12012\/[^\/]*)[\s\S]*/g, '$1');

			var urlModelSuffix = lineModels[currentModel].name;
			urlModelSuffix = urlModelSuffix.toLowerCase().trim().replace(/[\s]/g, '-').replace("!","").replace(":","").replace("'","").replace("´","").replace("&","und").replace("(","").replace(")","");
			var urlColorSuffix = lineColors[currentColor].name;
			urlColorSuffix = urlColorSuffix.toLowerCase().trim().replace(/[\s]/g, '-').replace("´","");
			currentLine += '/' + urlModelSuffix + '/' + urlColorSuffix;
			document.location.href = currentLine;
									
			if(lineModels[currentModel].offset == 'none'){				
				var opacitySuffix = "display:none;";		
			}else{			
				var opacitySuffix = "";	
				var reflectionOffset = -93;				
			}	

			$('#slideshow_current').append('<div class="slideshow_loading"></div>');
			var newImg = $('<img/>', {
				'src' : "en/image?type=slideshow&img=" + linePathPrefix + "_" + imgName + "_n" + colorId + "_1.png"
			});
			
			$('#slideshow_previous, #slideshow_next').html(newImg);
			$('#slideshow_previous, #slideshow_next').append('<img style="'+opacitySuffix+'margin-top:' + reflectionOffset + 'px" src="en/image?type=reflection&amp;img=' + linePathPrefix + '_' + imgName + '_n' + colorId + '_1.png">');
			
			if(newImg.get(0).complete) {
				ggl.callbackNextSlideshowImgLoaded(direction);
			} else {
				newImg.load(function() {
					ggl.callbackNextSlideshowImgLoaded(direction);
				});
			}
		},
		callbackNextSlideshowImgLoaded : function(direction) {
			$("#slideshow_current .slideshow_loading").remove();
			if(!animatingBag) {
				animatingBag = true;					
				if($('html').hasClass('ie8')) {
					$('#slideshow_current').html($('#slideshow_next').html());
					$('.slideshow_bag_model').html(lineModels[currentModel].name + ' <a href="javascript:void(0);" class="show_all_models lineBgColor">all models</a>');
					$('.slideshow_bag_color').html(lineColors[currentColor].name + ' <a href="javascript:void(0);" class="show_all_colors lineBgColor">all colors</a>');
					$('.slideshow_bag_dimensions').html(lineModels[currentModel].dimensions);
					$('.slideshow_bag_ar').empty();
					if(lineModels[currentModel].ar) {
						$('.slideshow_bag_ar').html('<a href="javascript:void(0);">TRY IT ON</a>');
					}
					ggl.updateColors(hightLightColor);
					animatingBag = false;
					zoomBlocked = false;
				} else {
					ggl.fadeOutBagInfo();
					$('.slideshow_loading').remove();					
					if(direction == 'nextBag') {
						ggl.slideBagLeft();
					} else if(direction == 'previousBag') {						
						ggl.slideBagRight();
					} else if(direction == 'previousColor') {
						ggl.slideBagDown();
					} else if(direction == 'nextColor') {
						ggl.slideBagUp();
					}
					document.title = lineModels[currentModel].name + ' in ' + lineColors[currentColor].name + document.title.replace(/[\s\S]*(\-[\s\S]+\-[\s]Bags[\s\S]+)/g, ' $1');

				}

				if(direction == 'previousColor' || direction == 'nextColor') {
					var newColor = lineColors[currentColor].color;
					var R = hexToR(newColor);
					var G = hexToG(newColor);
					var B = hexToB(newColor);
					$('#bags_gradient').css('background-image', '-moz-linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 80%)');
					$('#bags_gradient').css('background-image', '-webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
					$('#bags_gradient').css('background-image', '-o-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(' + R + ', ' + G + ', ' + B + ', 1) 100%)');
					$('#bags_gradient').css('background-image', '-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(' + R + ', ' + G + ', ' + B + ', 1)))');
					$('#ie_bags_gradient').attr('src', 'en/image?type=gradient&clr=' + newColor.replace('#', ''));
				}
			}
		},
		fadeOutBagInfo : function() {
			if(Modernizr.csstransforms3d) {
				$('.slideshow_bag_line, .slideshow_bag_model, .slideshow_bag_color, .slideshow_bag_dimensions, .slideshow_bag_ar').css({
					'-webkit-transition' : 'all 0.2s ease-out',
					'-o-transition' : 'all 0.2s ease-out',
					'-moz-transition' : 'all 0.2s ease-out',
					'-ms-transition' : 'all 0.2s ease-out'
				});
				setTimeout(function() {
					var animDelay = 0;
					$('#bag_info > div').each(function() {
						var el = $(this);
						setTimeout(function() {
							el.css({
								'opacity' : 0,
								'-webkit-transform' : 'translate3d(50px,0,0)',
								'-moz-transform' : 'translate3d(50px,0,0)',
								'-o-transform' : 'translate3d(50px,0,0)',
								'-ms-transform' : 'translate3d(50px,0,0)'
							});
						}, animDelay);
						animDelay += 80;
					});
				}, 5);
			} else {
				var animDelay = 0;
				$('#bag_info > div').each(function() {
					$(this).delay(animDelay).animate({
						'opacity' : 0,
						'margin-left' : 50
					}, {
						complete : function() {
							$(this).css('margin-left', -30);
						}
					});
					animDelay += 50;
				});
				setTimeout(function() {
					ggl.fadeInBagInfo();
				}, animDelay);
			}
		},
		fadeInBagInfo : function() {
			$('.slideshow_bag_model').html(lineModels[currentModel].name + ' <a href="javascript:void(0);" class="show_all_models lineBgColor">all models</a>');
			$('.slideshow_bag_color').html(lineColors[currentColor].name + ' <a href="javascript:void(0);" class="show_all_colors lineBgColor">all colors</a>');
			$('.slideshow_bag_dimensions').html(lineModels[currentModel].dimensions);
			$('.slideshow_bag_ar').empty();
			if(lineModels[currentModel].ar) {
				$('.slideshow_bag_ar').html('<a href="javascript:void(0);">TRY IT ON</a>');
			}
			ggl.updateColors(hightLightColor);

			if(Modernizr.csstransforms3d) {
				$('#bag_info > div').css({
					'-webkit-transition' : 'none',
					'-moz-transition' : 'none',
					'-o-transition' : 'none',
					'-ms-transition' : 'none'
				});
				$('#bag_info > div').css({
					'-webkit-transform' : 'translate3d(-30px,0,0)',
					'-o-transform' : 'translate3d(-30px,0,0)',
					'-moz-transform' : 'translate3d(-30px,0,0)',
					'-ms-transform' : 'translate3d(-30px,0,0)'
				});
				setTimeout(function() {
					$('#bag_info > div').css({
						'-webkit-transition' : 'all 0.2s ease-out',
						'-o-transition' : 'all 0.2s ease-out',
						'-moz-transition' : 'all 0.2s ease-out',
						'-ms-transition' : 'all 0.2s ease-out'
					});
					var animDelay = 0;
					$('#bag_info > div').each(function() {
						var el = $(this);
						setTimeout(function() {
							el.css({
								'opacity' : 1,
								'-webkit-transform' : 'translate3d(0,0,0)',
								'-o-transform' : 'translate3d(0,0,0)',
								'-moz-transform' : 'translate3d(0,0,0)',
								'-ms-transform' : 'translate3d(0,0,0)'
							});
						}, animDelay);
						animDelay += 80;
					});
				}, 5);
			} else {
				var animDelay = 0;
				$('#bag_info > div').each(function() {
					$(this).delay(animDelay).animate({
						'opacity' : 1,
						'margin-left' : 0
					});
					animDelay += 50;
				});
			}
		},
		slideBagDown : function() {
			if(Modernizr.csstransforms3d) {
				$('#slideshow_next').css({
					'-webkit-transition' : 'none',
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : -250,
					'-webkit-transform' : 'translate3d(0,-500px,0)',
					'-o-transform' : 'translate3d(0,-500px,0)',
					'-moz-transform' : 'translate3d(0,-500px,0)',
					'-ms-transform' : 'translate3d(0,-500px,0)'
				});
				$('#slideshow_current').css({
					'-webkit-transition' : 'all 0.2s ease-out',
					'-o-transition' : 'all 0.4s linear',
					'-moz-transition' : 'all 0.4s linear',
					'-ms-transition' : 'all 0.4s linear'
				});
				$('#slideshow_next').css({
					'-webkit-transition' : 'all 0.5s cubic-bezier(.1,1,.64,1)',
					'-o-transition' : 'all 0.7s linear',
					'-moz-transition' : 'all 0.7s ease-out',
					'-ms-transition' : 'all 0.7s linear'
				});
				document.getElementById('slideshow_next').addEventListener('webkitTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('transitionend', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('oTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('msTransitionEnd', slideshowTransitionendHandler, false);
				setTimeout(function() {
					$('#slideshow_current').css({
						'opacity' : 0,
						'-webkit-transform' : 'translate3d(0,500px,0)',
						'-moz-transform' : 'translate3d(0,500px,0)',
						'-o-transform' : 'translate3d(0,500px,0)',
						'-ms-transform' : 'translate3d(0,500px,0)'
					});
					$('#slideshow_next').css({
						'opacity' : 1,
						'-webkit-transform' : 'translate3d(0,0,0)',
						'-moz-transform' : 'translate3d(0,0,0)',
						'-o-transform' : 'translate3d(0,0,0)',
						'-ms-transform' : 'translate3d(0,0,0)'
					});
				}, 5);
			} else {
				$('#slideshow_current').animate({
					'margin-top' : 250,
					'opacity' : 0
				}, {
					'duration' : 200,
					'easing' : 'easeOutSine'
				});

				$('#slideshow_next').css({
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : -750
				}).delay(200).animate({
					'margin-top' : -250,
					'opacity' : 1
				}, {
					'duration' : 400,
					'easing' : 'easeOutExpo',
					'complete' : function() {
						$('#slideshow_current').html($('#slideshow_next').html());
						$('#slideshow_next').css({
							'display' : 'none',
							'margin-left' : 250,
							'opacity' : 0
						});
						$('#slideshow_current').css({
							'margin-left' : -250,
							'margin-top' : -250,
							'opacity' : 1
						});
						animatingBag = false;
						zoomBlocked = false;
					}
				});
			}

		},
		slideBagUp : function() {
			if(Modernizr.csstransforms3d) {
				$('#slideshow_next').css({
					'-webkit-transition' : 'none',
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : -250,
					'-webkit-transform' : 'translate3d(0,500px,0)',
					'-moz-transform' : 'translate3d(0,500px,0)',
					'-o-transform' : 'translate3d(0,500px,0)',
					'-ms-transform' : 'translate3d(0,500px,0)'
				});
				$('#slideshow_current').css({
					'-webkit-transition' : 'all 0.2s ease-out',
					'-o-transition' : 'all 0.4s ease-out',
					'-moz-transition' : 'all 0.4s ease-in',
					'-ms-transition' : 'all 0.4s ease-out'
				});
				$('#slideshow_next').css({
					'-webkit-transition' : 'all 0.5s cubic-bezier(.1,1,.64,1)',
					'-o-transition' : 'all 0.7s ease-out',
					'-moz-transition' : 'all 0.7s ease-out',
					'-ms-transition' : 'all 0.7s ease-out'
				});
				document.getElementById('slideshow_next').addEventListener('webkitTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('transitionend', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('oTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('msTransitionEnd', slideshowTransitionendHandler, false);
				
				setTimeout(function() {
					$('#slideshow_current').css({
						'opacity' : 0,
						'-webkit-transform' : 'translate3d(0,-500px,0)',
						'-o-transform' : 'translate3d(0,-500px,0)',
						'-moz-transform' : 'translate3d(0,-500px,0)',
						'-ms-transform' : 'translate3d(0,-500px,0)'
					});
					$('#slideshow_next').css({
						'opacity' : 1,
						'-webkit-transform' : 'translate3d(0,0,0)',
						'-moz-transform' : 'translate3d(0,0,0)',
						'-o-transform' : 'translate3d(0,0,0)',
						'-ms-transform' : 'translate3d(0,0,0)'
					});
				}, 5);
			} else {
				$('#slideshow_current').animate({
					'margin-top' : -750,
					'opacity' : 0
				}, {
					'duration' : 200,
					'easing' : 'easeOutSine'
				});

				$('#slideshow_next').css({
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : 250
				}).delay(200).animate({
					'margin-top' : -250,
					'opacity' : 1
				}, {
					'duration' : 400,
					'easing' : 'easeOutExpo',
					'complete' : function() {
						$('#slideshow_current').html($('#slideshow_next').html());
						$('#slideshow_next').css({
							'display' : 'none',
							'margin-left' : 250,
							'opacity' : 0
						});
						$('#slideshow_current').css({
							'margin-left' : -250,
							'margin-top' : -250,
							'opacity' : 1
						});
						animatingBag = false;
						zoomBlocked = false;
					}
				});
			}
		},
		slideBagLeft : function() {
		
			if(Modernizr.csstransforms3d) {
				
				$('#slideshow_next').css({
					'-webkit-transition' : 'none',
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : -250,
					'-webkit-transform' : 'translate3d(500px,0,0)',
					'-o-transform' : 'translate3d(500px,0,0)',
					'-ms-transform' : 'translate3d(500px,0,0)',
					'-moz-transform' : 'translate3d(500px,0,0)'
				});
				$('#slideshow_current').css({
					'-webkit-transition' : 'all 0.2s ease-out',
					'-o-transition' : 'all 0.4s ease-out',
					'-moz-transition' : 'all 0.4s ease-out',
					'-ms-transition' : 'all 0.4s ease-out'
				});
				$('#slideshow_next').css({
					'-webkit-transition' : 'all 0.5s cubic-bezier(.1,1,.64,1)',
					'-o-transition' : 'all 0.7s ease-out',
					'-moz-transition' : 'all 0.7s ease-out',
					'-ms-transition' : 'all 0.7s ease-out'
				});
				document.getElementById('slideshow_next').addEventListener('webkitTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('transitionend', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('oTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('msTransitionEnd', slideshowTransitionendHandler, false);
				
				setTimeout(function() {
					$('#slideshow_current').css({
						'opacity' : 0,
						'-webkit-transform' : 'translate3d(-500px,0,0)',
						'-o-transform' : 'translate3d(-500px,0,0)',
						'-moz-transform' : 'translate3d(-500px,0,0)',
						'-ms-transform' : 'translate3d(-500px,0,0)'
					});
					$('#slideshow_next').css({
						'opacity' : 1,
						'-webkit-transform' : 'translate3d(0,0,0)',
						'-o-transform' : 'translate3d(0,0,0)',
						'-moz-transform' : 'translate3d(0,0,0)',
						'-ms-transform' : 'translate3d(0,0,0)'
					});
				}, 5);
			} else {
				$('#slideshow_current').animate({
					'margin-left' : -750,
					'opacity' : 0
				}, {
					'duration' : 200,
					'easing' : 'easeOutSine'
				});
				$('#slideshow_next').css('display', 'block').delay(200).animate({
					'margin-left' : -250,
					'opacity' : 1
				}, {
					'duration' : 400,
					'easing' : 'easeOutExpo',
					'complete' : function() {
						$('#slideshow_current').html($('#slideshow_next').html());
						$('#slideshow_next').css({
							'display' : 'none',
							'margin-left' : 250,
							'opacity' : 0
						});
						$('#slideshow_current').css({
							'margin-left' : -250,
							'opacity' : 1
						});
						animatingBag = false;
						zoomBlocked = false;
					}
				});
			}
		},
		slideBagRight : function() {
			if(Modernizr.csstransforms3d) {
				$('#slideshow_next').css({
					'-webkit-transition' : 'none',
					'display' : 'block',
					'margin-left' : -250,
					'margin-top' : -250,
					'-webkit-transform' : 'translate3d(-500px,0,0)',
					'-moz-transform' : 'translate3d(-500px,0,0)',
					'-o-transform' : 'translate3d(-500px,0,0)',
					'-ms-transform' : 'translate3d(-500px,0,0)'
				});
				$('#slideshow_current').css({
					'-webkit-transition' : 'all 0.2s ease-out',
					'-moz-transition' : 'all 0.4s ease-out',
					'-o-transition' : 'all 0.4s ease-out',
					'-ms-transition' : 'all 0.4s ease-out'
				});
				$('#slideshow_next').css({
					'-webkit-transition' : 'all 0.5s cubic-bezier(.1,1,.64,1)',
					'-moz-transition' : 'all 0.7s ease-out',
					'-o-transition' : 'all 0.7s ease-out',
					'-ms-transition' : 'all 0.7s ease-out'
				});
				document.getElementById('slideshow_next').addEventListener('webkitTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('transitionend', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('oTransitionEnd', slideshowTransitionendHandler, false);
				document.getElementById('slideshow_next').addEventListener('msTransitionEnd', slideshowTransitionendHandler, false);
				
				setTimeout(function() {
					$('#slideshow_current').css({
						'opacity' : 0,
						'-webkit-transform' : 'translate3d(500px,0,0)',
						'-o-transform' : 'translate3d(500px,0,0)',
						'-moz-transform' : 'translate3d(500px,0,0)',
						'-ms-transform' : 'translate3d(500px,0,0)'
					});
					$('#slideshow_next').css({
						'opacity' : 1,
						'-webkit-transform' : 'translate3d(0,0,0)',
						'-o-transform' : 'translate3d(0,0,0)',
						'-ms-transform' : 'translate3d(0,0,0)',
						'-moz-transform' : 'translate3d(0,0,0)'
					});
				}, 5);
			} else {
				$('#slideshow_current').animate({
					'margin-left' : 250,
					'opacity' : 0
				}, {
					'duration' : 200,
					'easing' : 'easeOutSine'
				});
				$('#slideshow_previous').css('display', 'block').delay(200).animate({
					'margin-left' : -250,
					'opacity' : 1
				}, {
					'duration' : 400,
					'easing' : 'easeOutExpo',
					'complete' : function() {
						$('#slideshow_current').html($('#slideshow_next').html());
						$('#slideshow_previous').css({
							'display' : 'none',
							'margin-left' : -750,
							'opacity' : 0
						});
						$('#slideshow_current').css({
							'margin-left' : -250,
							'opacity' : 1
						});
						animatingBag = false;
						zoomBlocked = false;
					}
				});
			}
		},
		countSlashes : function(link) {
			var count = 0;
			link = link.replace('http://', '');
			var pos = link.indexOf("/");
			while(pos != -1) {
				count++;
				pos = link.indexOf("/", pos + 1);
			}
			return count;
		},
		loadUrl : function(link, linkType) {
			var hash = document.location.href;

			try {
				piwikTracker.trackPageView();
			} catch( err ) {
			}

			if(hash.indexOf('the-stories/') != -1) {
				ggl.loadStory(hash.replace('#!/', ''));
			}
			
			if(hash.indexOf('bags/collection12012/') != -1 && ggl.countSlashes(hash) == 5) {
				ggl.resetBags();
				ggl.loadLine(hash.replace('#!/', '') + '?xml=true');
				ggl.setCurrentColumn('left');
				
			}

			if(hash.indexOf('bags/collection12012/') != -1 && ggl.countSlashes(hash) > 5 && currentColumn == 'middle') {
				ggl.resetBags();
				
				var lineUrl = hash.replace(/([\s\S]*collection12012\/[^\/]*)[\d\D]*/g, '$1');			
				ggl.loadLine(lineUrl.replace('#!/', '') + '?xml=true', true);
				//ggl.setCurrentColumn('left');
			}

			if(!deepLinkFirst && hash.indexOf('bags/collection12012/') != -1 && ggl.countSlashes(hash) > 5 && currentColumn == 'left') {
				
				var cModel = unescape(hash.replace(/[\s\S]+\/([\s\S]+)\/([\s\S]+)/g, '$1'));
				var cColor = unescape(hash.replace(/[\s\S]+\/([\s\S]+)\/([\s\S]+)/g, '$2'));
				
				for(var i = 0, len = lineModels.length; i < len; i++) {
					if(lineModels[i].name.trim().replace(/[\s]/g, '-').replace("!","").replace(":","").replace("'","").replace("´","").replace("&","und").toLowerCase() == cModel) {
						cModel = i;
					}
				}
				for(var i = 0, len = lineColors.length; i < len; i++) {
					if(lineColors[i].name.trim().replace(/[\s]/g, '-').toLowerCase().replace("´","") == cColor) {
						cColor = i;
					}
				}
				if(currentModel != cModel || currentColor != cColor) {
					if($('#line_slideshow').css('display') == 'none') {
						var lineUrl = hash.replace(/([\s\S]*collection12012\/[^\/]*)[\d\D]*/g, '$1');
						ggl.loadLine(lineUrl.replace('#!/', '') + '?xml=true', true);
						$('#the_bags').css('display', 'none');
					} else {
						ggl.switchBag(cModel, cColor);
					}
				}
			}

			if(hash.substring(hash.length - 5, hash.length) == '12012') {
				ggl.loadCollectionMarkup();
			}

			if(hash.substring(hash.length - 11, hash.length) == 'the-stories') {
				ggl.loadStoriesMarkup();
			}

			if(hash.indexOf('imprint') != -1 || hash.indexOf('contact') != -1 || hash.indexOf('creditcard') != -1 || hash.indexOf('spotted') != -1 || hash.indexOf('storefinder') != -1) {
				ggl.openMeta(hash.replace('#!/', ''));
			}
			
			if(hash.indexOf('archive') != -1) {			
				// TEST REPLACE URL LATER	
				archive.loadArchive("/en/archive");
			}

			if(ggl.countSlashes(hash) <= 2 && $('.story').size() == 0) {
				ggl.loadMoreStories();
			}

			if(hash.charAt(hash.length - 2) == '!' || hash.indexOf('#!') == -1) {
				window.location.href = "#!/";
				ggl.goToMiddle();
			}
			deepLinkFirst = false;

		},	
		goToLeft : function(callback) {
			$('html').css('overflow-y', 'hidden');
			$('#fake_scroller').css('display', 'none');
			//$('#header').css('width',$(window).width()-scrollbarWidth());
			if(Modernizr.csstransforms3d && Modernizr.touch) {
				$('#columns_wrapper').removeClass('story').addClass('bags');
				setTimeout(function() {
					if(callback) {
						callback.call();
					}
					
					
				}, 600);
			} else {
				$('#columns_wrapper').animate({
					'margin-left' : '0%'
				}, {
					duration : 400,
					easing : 'easeOutSine',
					complete : function() {						
						$('#scroller_right').empty();
						$('#story_column, #scroller_middle').hide();
						if(callback) {
							setTimeout(function() {
								callback.call();
							}, 200);
						}
					}
				});
			}
	
			ggl.setCurrentColumn('left');

		},
		goToMiddle : function() {
			document.title = 'Official George Gina & Lucy Website';

			if($('.story').size() == 0) {
				ggl.loadMoreStories();
			}
			$('#scroller_middle').show();

			$('.go_from_bags_to_blog, .go_from_bags_to_story, .go_from_story_to_blog').stop().css({
				'opacity' : 0,
				'display' : 'none'
			});
			$('#meta_column').animate({
				opacity : 0
			}, {
				duration : 300,
				complete : function() {
					$(this).css('display', 'none');
				}
			});

			$('.rex-current, .rex-active').css({
				color : '#fff'
			}).removeClass('rex-current').removeClass('rex-active');

			ggl.setCurrentColumn('middle');
			$('html.no-touch').css('overflow-y', 'scroll');
			$('#fake_scroller').css('display', 'block');
			$('#header').css('width', '100%');
			ggl.resize();
			$(window).scrollTop(activePost * $(window).height());

			setTimeout(function() {
				ggl.slideOutStoryToBagsLink();
				ggl.slideOutStoryToBlogLink();

				if(Modernizr.csstransforms3d && Modernizr.touch) {
					$('#columns_wrapper').removeClass('story').removeClass('bags');
				} else {
					$('#columns_wrapper').animate({
						'margin-left' : '-100%'
					}, {
						duration : 400,
						easing : 'easeOutSine',
						complete : function() {
							$('#scroller_right').empty();
							$('#story_column').hide();
						}
					});
				}
			}, 20);
			setTimeout(function() {
				ggl.resetBags();
			}, 420);
		},
		init : function() {

			if( typeof String.prototype.trim !== 'function') {
				String.prototype.trim = function() {
					return this.replace(/^\s+|\s+$/g, '');
				}
			}
			String.prototype.myCapitalize = function() {
				return this.replace(/(^|\s|\-)([a-z])/g, function(m, p1, p2) {
					return p1 + p2.toUpperCase();
				});
			};
			//ggl.loadLine('line.xml');
			if(navigator.userAgent.match(/(iPad|iPhone);.*CPU.*OS 5_\d/i)) {

			} else {
				if(Modernizr.touch && Modernizr.csstransforms3d) {
					touchMiddle = new touchClass(document.getElementById('columns_wrapper'), 'ios4');
				}
			}

			window.onorientationchange = function() {
				$(window).scrollTop(0);
			}
			var currentHash = window.location.href;
			ggl.loadUrl(currentHash);
			$.address.init(function(event) {

			}).change(function(event) {
				ggl.loadUrl();
			});
			touchMiddle = new touchClass(document.getElementById('scroller_middle'), 'middle');
			touchSlideshow = new touchClass(document.getElementById('slideshow_current'), 'slideshow');
			touchSlideshow2 = new touchClass(document.getElementById('slideshow_next'), 'slideshow');
			touchStory = new touchClass(document.getElementById('scroller_right'), 'story');
			windowHeight = $(window).height();
			windowWidth = $(window).width();
			$('.story').css({
				'height' : windowHeight,
				'top' : windowHeight
			});
			$('.story').eq(0).css({
				top : 0
			});
			
			
			// INIT ARCHIVE EVENT LISTENER
			archive.init();			
			
			if($('.story').size() == 0 && ggl.countSlashes(currentHash) <= 2) {
				ggl.loadMoreStories();
			}

			// SAFARI VIDEO FALLBACK PLAY/PAUSE TOGGLE
			$('.videoCanvas, .video_toggle').live('mouseenter', function() {
				$(this).parent().find('.video_toggle').css('display', 'block').stop().delay(20).animate({
					opacity : 1
				}, {
					duration : 200
				});
			});

			$('.videoCanvas').live('mouseleave', function() {
				$(this).parent().find('.video_toggle').stop().animate({
					opacity : 0
				}, {
					complete : function() {
						$(this).css('display', 'none');
					}
				});
			});

			$('.video_toggle').live('click', function() {
				if($(this).hasClass('paused')) {
					$(this).removeClass('paused');
					if(canvasVideoPlaying.ended) {
						canvasVideoPlaying.currentTime = 0.0;
					}
					canvasVideoPlaying.play();
					if(canvasVideoPlaying.ended) {
						videoCanvas.drawVideo(myvideo, width, height);
					}
				} else {
					$(this).addClass('paused');
					canvasVideoPlaying.pause();
				}
			});
			// WHERE TO BUY LINK
			$('.slideshow_bag_where_to_buy a').live('click', function() {
				ggl.showWhereToBuy();
			});
			// OPEN LINE FROM SUBMENU
			$('#main_menu_list ul > li:first > ul > li:first ul a').live('click', function() {
				var link = $(this).attr('href');
				document.location.href = '#!' + link;
				return false;
			});
			// OPEN STORY FROM SUBMENU
			$('#main_menu_list ul > li:first > ul > li:eq(1) ul a').live('click', function() {
				var link = $(this).attr('href');
				document.location.href = '#!' + link;
				return false;
			});
			// OPEN STORY
			$('.story_link').live('click', function() {
				var link = $(this).attr('href');
				activePost = $('.story .story_link').index($(this));
				$('#the_stories, #the_stories_gradient_wrapper, #the_stories_bg').css({
					'opacity' : 0,
					'display' : 'none'
				});
				//ggl.loadStory(link);
				ggl.setCurrentColumn('right');
				document.location.href = '#!' + link;
				return false;
			});
			// GO TO LINE OVERVIEW
			$('.line_link').live('click', function() {
				var xml = $(this).attr('data-xml');
				activePost = $('.story .line_link').index($(this));

				$('#the_bags').css({
					'opacity' : 0,
					'display' : 'none'
				});
				//ggl.loadLine(xml);
				document.location.href = '#!' + xml.replace('?xml=true', '');

				return false;
			});
			$('.article_bag').live('click', function() {
				var link = $(this).attr('data-link');
				
				document.location.href = '#!' + link;
			});
			// SHOW ALL MODELS
			$('.show_all_models').live('click', function() {
				ggl.showAll('models');
			});
			// SHOW ALL COLORS
			$('.show_all_colors').live('click', function() {
				ggl.showAll('colors');
			});
			// CLOSE SHOW ALL MODELS/COLORS LIGHTBOX AND SHOW SELECTED BAG/COLOR
			$('.close_show_all').live('click', function() {
				var thisModel = $(this).parent().attr('data-model');
				var thisColor = $(this).parent().attr('data-color');
				var type = $(this).parent().attr('data-type');
				ggl.closeShowAll(type, thisModel, thisColor);
			});
			// CLOSE SHOW ALL MODELS/COLORS LIGHTBOX AND GO BACK TO SLIDESHOW
			$('#line_show_all_close, #where_to_buy_close').click(function() {
				var thisModel = currentModel;
				var thisColor = currentColor;
				var type = '';
				if($(this).attr('id') == 'where_to_buy_close') {
					type = 'wtb';
				}
				ggl.closeShowAll(type, thisModel, thisColor);
				return false;
			});
			// OPEN ZOOM
			$('.no-touch .slideshow_frame').live('click', function() {

				if(!zoomBlocked) {
					ggl.loadZoom();
				}
				return false;
			});
			// CLOSE ZOOM
			$('#line_zoom_close').click(function() {
				ggl.closeZoom();
				return false;
			});
			//ZOOM MOUSE MOVE ON DESKTOP
			$('.no-touch #line_zoom').mousemove(function(event) {
				if(ggl.zoomLoaded()) {
					var mouseTop = event.pageY;
					var imgW = $(window).width();
					var offsetY = $('#line_zoom_img img').css('top').replace('px', '') * 1;

					var bagMTop = -(imgW - $(window).height()) * mouseTop / $(window).height() - offsetY;
					$('#line_zoom_img img').css({
						'margin-top' : bagMTop
					});
				}
				//ggl.closeZoom();
				return false;
			});
			$('.metamenu_item').live('click', function() {
				//var link = $(this).find('a').attr('href');
				var link = $(this).find('a').not('.new_window').attr('href');
				if(link) {
					document.location.href = '#!' + link;
				}

				//ggl.openMeta(link);
				return false;
			});
			// SHOW COLLECTION
			$('#main_menu_list .nav_1 .level1, #main_menu_list .nav_1 .nav_1 .level2').live('click', function() {
				//ggl.loadCollectionMarkup();
				var link = $(this).attr('href');
				document.location.href = '#!' + link;
				return false;
			});
			// SHOW ALL STORIES
			$('#main_menu_list .nav_1 .nav_2 .level2').live('click', function() {
				var link = $(this).attr('href');
				document.location.href = '#!' + link;
				//ggl.loadStoriesMarkup();
				return false;
			});
			//CLICK ON STORIES THUMB TO OPEN STORY
			$('.storie_thumb').live('click', function() {
				var link = $(this).attr('data-link');
				ggl.setCurrentColumn('right');
				document.location.href = '#!' + link;
				return false;
			});
			//CLICK ON COLLECTION THUMB TO OPEN LINE
			$('.bag_thumb').live('click', function() {
				var xml = $(this).attr('data-xml');
				ggl.resetBags();
				$('#the_bags').animate({
					'opacity' : 0,
					'margin-top' : 30
				}, {
					duration : 400,
					complete : function() {
						$(this).css('display', 'none');
					}
				});
				setTimeout(function() {
					document.location.href = '#!' + xml.replace('?xml=true', '');
					//ggl.loadLine(xml);
				}, 400);
				return false;
			});
			// GO BACK FROM BAGS TO BLOG
			$('.go_from_bags_to_blog').click(function() {
				ggl.goToMiddle();

				setTimeout(function() {
					ggl.resetBags();
				}, 500);

				$('.rex-current, .rex-active').css({
					color : '#fff'
				}).removeClass('rex-current').removeClass('rex-active');

				window.location.href = '#!/';
				return false;
			});
			// GO BACK FROM STORY TO BLOG
			$('.go_from_story_to_blog').click(function() {
				ggl.goToMiddle();

				$('#main_menu ul ul').css('display', 'none');
				$('#main_menu ul a').removeClass('active').css('color', '#fff');
				$('.rex-current, .rex-active').css({
					color : '#fff'
				}).removeClass('rex-current').removeClass('rex-active');

				window.location.href = '#!/';
				return false;
			});
			// SHOW BAG DETAILS
			$('.show_bag').live('click', function() {
				var thisModel = $(this).parent().attr('data-model');
				var thisColor = $(this).parent().attr('data-color');

				ggl.showBag(thisModel, thisColor);
			});
			//NEXT BAG MODEL
			$('#next_bag').click(function() {
				ggl.changeBag('nextBag');
			});
			//PREVIOUS BAG MODEL
			$('#previous_bag').click(function() {
				ggl.changeBag('previousBag');
			});
			//NEXT BAG COLOR
			$('#next_color').click(function() {
				ggl.changeBag('nextColor');
			});
			//PREVIOUS BAG COLOR
			$('#previous_color').click(function() {
				ggl.changeBag('previousColor');
			});
			
			if(Modernizr.touch && Modernizr.csstransforms3d) {
				
				// IPAD & OTHER TOUCH DEVICES PARALLAX UPDATE
				$('#scroller_right').scroll(function() {

					var topScroll = $('#scroller_right').scrollTop();
					//var topScroll = $(window).scrollTop();
					var topScrollGlobal = topScroll;
					var assetFactor = redaxoCurrentImgWidth / 2000;

					var tempHeight = 0, firstFoundHeight = 0, found = false, firstVisible = 0, bgParallaxFactor = 0.3;

					$('#scroller_right .parallax_bg').each(function(index) {
						if(!found) {
							firstFoundHeight = tempHeight;
							tempHeight += $(this).height();
							if(tempHeight > topScroll) {
								found = true;
								firstVisible = index;
							}
						}
					});
					topScroll = topScroll - firstFoundHeight;

					var el = $('#scroller_right .parallax_bg').eq(firstVisible), elHeight = el.height();

					el.css({
						"background-position" : "0% " + (topScroll * bgParallaxFactor) + "px"
					});

					var nextEl = $('#scroller_right .parallax_bg').eq(firstVisible + 1), nextElHeight = nextEl.height();
					nextEl.css({
						"background-position" : "0% " + ((topScroll - elHeight) * bgParallaxFactor) + "px"
					});

					var nextnextEl = $('#scroller_right .parallax_bg').eq(firstVisible + 2), nextnextElHeight = nextnextEl.height();
					nextnextEl.css({
						"background-position" : "0% " + ((topScroll - elHeight - nextElHeight) * bgParallaxFactor) + "px"
					});

					$('#scroller_right .parallax_item').each(function() {
						var speedX = ($(this).attr('data-speedX') == undefined) ? 0 : $(this).attr('data-speedX') * 1;
						var speedY = ($(this).attr('data-speedY') == undefined) ? 0 : $(this).attr('data-speedY') * 1;
						var speedAlpha = ($(this).attr('data-speedAlpha') == undefined) ? 0 : $(this).attr('data-speedAlpha') * 1;
						var offsetY = ($(this).attr('data-offsetY') == undefined) ? 0 : $(this).attr('data-offsetY') * 1;
						var offsetAlpha = ($(this).attr('data-offsetAlpha') == undefined) ? 0 : $(this).attr('data-offsetAlpha') * 1;
						var touchTop = ($(this).attr('data-touchtop') == undefined) ? 0 : $(this).attr('data-touchtop');						
						if(touchTop == 0){
							touchTop = $(this).css("top");
						}
										
						$(this).css({
							'top': touchTop,
							'margin-top' : ((topScrollGlobal) * -speedY * assetFactor),
							'margin-left' : (topScrollGlobal * -speedX * assetFactor),
							'-webkit-transform' : 'rotate(' + (((topScrollGlobal - offsetY) * -speedAlpha * -0.5 * assetFactor) + offsetAlpha) + 'deg)',
							'-moz-transform' : 'rotate(' + (((topScrollGlobal - offsetY) * -speedAlpha * -0.5 * assetFactor) + offsetAlpha) + 'deg)'
						});
					});
				});
				$('#scroller_middle').scroll(function() {
					var topScroll = $('#scroller_middle').scrollTop();

					var firstVisibleIndex = Math.floor(topScroll / windowHeight);
					var firstScrollTop = (topScroll - (firstVisibleIndex * windowHeight));
					var firstVisible = $('.story').eq(firstVisibleIndex);

					//if(firstVisibleIndex == $('.story').size() - 2) {
					if(topScroll == ($('.story').size() - 1) * $(window).height() && moreStories) {
						ggl.loadMoreStories();
					}

					var firstPositionH = firstVisible.css('background-position');

					if(firstPositionH) {
						firstPositionH = firstPositionH.replace(/([\d]*[%|px])\s[\-|\d|\.]*[%|px]*/g, '$1 ' + (firstScrollTop / -4) + 'px');
					} else {
						firstPositionH = '0% ' + (firstScrollTop / -4) + 'px';
					}

					firstVisible.stop().css({
						"background-position" : firstPositionH
					});

					firstVisible.find('.blog_parallax_item').each(function() {
						var speedX = ($(this).attr('data-speedX') == undefined) ? 0 : $(this).attr('data-speedX') * 1;
						var speedY = ($(this).attr('data-speedY') == undefined) ? 0 : $(this).attr('data-speedY') * 1;
						var speedAlpha = ($(this).attr('data-speedAlpha') == undefined) ? 0 : $(this).attr('data-speedAlpha') * 1;
						$(this).css({
							'margin-top' : Math.round(firstScrollTop * -speedY),
							'margin-left' : (firstScrollTop * -speedX),
							'-moz-transform' : 'rotate(' + (firstScrollTop * -speedAlpha * 0.5) + 'deg)',
							'-webkit-transform' : 'rotate(' + (firstScrollTop * -speedAlpha * 0.5) + 'deg) translate3d(0,0,0)',
							'-webkit-transform' : 'rotate(' + (firstScrollTop * -speedAlpha * 0.5) + 'deg)'
						});
					});
					var nextScrollTop = (topScroll - ((firstVisibleIndex + 1) * windowHeight));
					var nextVisible = $('.story').eq(firstVisibleIndex + 1);

					var nextPositionH = nextVisible.css('background-position');

					if(nextPositionH) {
						nextPositionH = nextPositionH.replace(/([\d]*[%|px])\s[\-|\d|\.]*[%|px]*/g, '$1 ' + (nextScrollTop / -4) + 'px');
					} else {
						nextPositionH = '0% ' + (nextScrollTop / -4) + 'px';
					}

					nextVisible.stop().css({
						"background-position" : nextPositionH
					});

					nextVisible.find('.blog_parallax_item').each(function() {
						var speedX = ($(this).attr('data-speedX') == undefined) ? 0 : $(this).attr('data-speedX') * 1;
						var speedY = ($(this).attr('data-speedY') == undefined) ? 0 : $(this).attr('data-speedY') * 1;
						var speedAlpha = ($(this).attr('data-speedAlpha') == undefined) ? 0 : $(this).attr('data-speedAlpha') * 1;

						$(this).css({
							'margin-top' : Math.round(nextScrollTop * -speedY),
							'margin-left' : (nextScrollTop * -speedX),
							'-moz-transform' : 'rotate(' + (nextScrollTop * -speedAlpha * 0.5) + 'deg)',
							'-webkit-transform' : 'rotate(' + (nextScrollTop * -speedAlpha * 0.5) + 'deg) translate3d(0,0,0)',
							'-webkit-transform' : 'rotate(' + (nextScrollTop * -speedAlpha * 0.5) + 'deg)'
						});
					});
				});
			} else {
				// DESKTOP PARALLAX UPDATE
				$(window).scroll(function() {
					var topScroll = $(window).scrollTop();

					if(currentColumn == 'middle' && topScroll >= 0 && topScroll <= $('#fake_scroller').height()) {
						ggl.updateBlogOnScroll();
					}
					if(currentColumn == 'right' && topScroll >= 0 && topScroll <= $('#fake_scroller').height()) {
						ggl.updateStoryOnScroll();
					}
				});
			}

			ggl.resize();
			storefinder.init();

		},
		updateStoryOnScroll : function() {

			var topScroll = $(window).scrollTop();
			var topScrollGlobal = $(window).scrollTop();

			var tempHeight = 0, firstFoundHeight = 0, found = false, firstVisible = 0, bgParallaxFactor = -0.3;

			var assetFactor = redaxoCurrentImgWidth / 2000;

			$('#scroller_right .parallax_bg').each(function(index) {
				if(!found) {
					firstFoundHeight = tempHeight;
					tempHeight += $(this).height();
					if(tempHeight > topScroll) {
						found = true;
						firstVisible = index;
					}
				}
			});
			topScroll = topScroll - firstFoundHeight;
			$('#scroller_right .parallax_bg:lt(' + firstVisible + ')').css({
				top : -2000
			});
			var currentBg = $('#scroller_right .parallax_bg').eq(firstVisible), elHeight = currentBg.height();
			var firstTop = (topScroll * bgParallaxFactor );

			var currentAlign = currentBg.attr('data-align');
			currentBg.css({
				"background-position" : currentAlign + " " + (topScroll * bgParallaxFactor) + "px",
				top : -topScroll
			});

			var nextBg = $('#scroller_right .parallax_bg').eq(firstVisible + 1), nextElHeight = nextBg.height();
			var nextAlign = nextBg.attr('data-align');
			nextBg.css({
				"background-position" : nextAlign + " " + ((topScroll - elHeight) * bgParallaxFactor) + "px",
				top : -topScroll + elHeight
			});

			var nextnextBg = $('#scroller_right .parallax_bg').eq(firstVisible + 2), nextnextElHeight = nextnextBg.height();
			var nextnextAlign = nextnextBg.attr('data-align');
			nextnextBg.css({
				"background-position" : nextnextAlign + " " + ((topScroll - elHeight - nextElHeight) * bgParallaxFactor) + "px",
				top : -topScroll + elHeight + nextElHeight
			});

			$('#scroller_right .parallax_item').each(function() {
				var speedX = ($(this).attr('data-speedXb') == undefined) ? 0 : $(this).attr('data-speedXb') * 1;
				var speedY = ($(this).attr('data-speedYb') == undefined) ? 0 : $(this).attr('data-speedYb') * 1;
				var speedAlpha = ($(this).attr('data-speedAlphab') == undefined) ? 0 : $(this).attr('data-speedAlphab') * 1;
				var offsetY = ($(this).attr('data-offsetY') == undefined) ? 0 : $(this).attr('data-offsetY') * 1;
				var offsetAlpha = ($(this).attr('data-offsetAlpha') == undefined) ? 0 : $(this).attr('data-offsetAlpha') * 1;
								
				
				$(this).css({					
					'margin-top' : ((topScrollGlobal) * -speedY ),
					'margin-left' : (topScrollGlobal * -speedX * assetFactor),
					'-webkit-transform' : 'rotate(' + (((topScrollGlobal - offsetY) * -speedAlpha * -0.5 * assetFactor) + offsetAlpha) + 'deg)',
					'-moz-transform' : 'rotate(' + (((topScrollGlobal - offsetY) * -speedAlpha * -0.5 * assetFactor) + offsetAlpha) + 'deg)'
				});
			});
		},
		updateBlogOnScroll : function() {
		
			var topScroll = $(window).scrollTop();
			var firstVisibleIndex = Math.floor(topScroll / windowHeight);
			var currentStory = $('.story').eq(firstVisibleIndex);
			var nextStory = $('.story').eq(firstVisibleIndex + 1);
			var scrollOffset = topScroll % windowHeight;

			var nextscrollOffset = scrollOffset - windowHeight;

			var firstPositionH = currentStory.css('background-position');
			$('.story:lt(' + firstVisibleIndex + ')').css({
				'top' : -windowHeight
			});
			$('.story:gt(' + (firstVisibleIndex + 1) + ')').css({
				'top' : windowHeight
			});

			if(topScroll == ($('.story').size() - 1) * $(window).height() && moreStories) {
				ggl.loadMoreStories();
			}

			if(firstPositionH) {
				firstPositionH = firstPositionH.replace(/([\d]*[%|px])\s[\-|\d|\.]*[%|px]*/g, '$1 ' + (scrollOffset / -4) + 'px');
			} else {
				firstPositionH = '0% ' + (scrollOffset / -4) + 'px';
			}
			currentStory.stop().css({
				"background-position" : firstPositionH,
				top : -scrollOffset
			});
			currentStory.find('.blog_parallax_item').each(function() {
				var speedX = ($(this).attr('data-speedXbefore') == undefined) ? 0 : $(this).attr('data-speedXbefore') * 1;
				var speedY = ($(this).attr('data-speedYbefore') == undefined) ? 0 : $(this).attr('data-speedYbefore') * 1;
				var speedScale = ($(this).attr('data-scalebefore') == undefined) ? 0 : $(this).attr('data-scalebefore') * 1;
				var speedAlpha = ($(this).attr('data-speedAlphabefore') == undefined) ? 0 : $(this).attr('data-speedAlphabefore') * 1;
				var speedOpacity = ($(this).attr('data-opacitybefore') == undefined) ? 1 : $(this).attr('data-opacitybefore') * 1;
				var newOpacity = 1;

				$(this).css({
					'margin-top' : Math.round(scrollOffset * -speedY),
					'margin-left' : (scrollOffset * -speedX),
					'opacity' : newOpacity,
					'-moz-transform' : 'rotate(' + (scrollOffset * -speedAlpha * 0.5) + 'deg) scale(' + (1 + (scrollOffset * speedScale * 0.02)) + ')',
					'-webkit-transform' : 'rotate(' + (scrollOffset * -speedAlpha * 0.5) + 'deg) scale(' + (1 + (scrollOffset * speedScale * 0.02)) + ')',
					
				});
			});
			var nextPositionH = nextStory.css('background-position');
			if(nextPositionH) {
				nextPositionH = nextPositionH.replace(/([\d]*[%|px])\s[\-|\d|\.]*[%|px]*/g, '$1 ' + ((windowHeight - scrollOffset) / 4 ) + 'px');
			} else {
				nextPositionH = '0% ' + (scrollOffset / -4) + 'px';
			}
			nextStory.stop().css({
				"background-position" : nextPositionH,
				top : -scrollOffset + windowHeight
			});
			nextStory.find('.blog_parallax_item').each(function() {
				var speedX = ($(this).attr('data-speedXafter') == undefined) ? 0 : $(this).attr('data-speedXafter') * 1;
				var speedY = ($(this).attr('data-speedYafter') == undefined) ? 0 : $(this).attr('data-speedYafter') * 1;
				var speedScale = ($(this).attr('data-scaleafter') == undefined) ? 0 : $(this).attr('data-scaleafter') * 1;
				var speedAlpha = ($(this).attr('data-speedAlphaafter') == undefined) ? 0 : $(this).attr('data-speedAlphaafter') * 1;
				$(this).css({
					'margin-top' : Math.round(nextscrollOffset * -speedY),
					'margin-left' : (nextscrollOffset * -speedX),
					'-moz-transform' : 'rotate(' + (nextscrollOffset * -speedAlpha * 0.5) + 'deg) scale(' + (1 + (nextscrollOffset * speedScale * 0.02)) + ')',
					'-webkit-transform' : 'rotate(' + (nextscrollOffset * -speedAlpha * 0.5) + 'deg) scale(' + (1 + (nextscrollOffset * speedScale * 0.02)) + ') translate3d(0,0,0)',
					'-webkit-transform' : 'rotate(' + (nextscrollOffset * -speedAlpha * 0.5) + 'deg) scale(' + (1 + (nextscrollOffset * speedScale * 0.02)) + ')'
				});
			});
			// THE CHECK > 0 SEEMS TO BE REQUIRED TO AVOID POSITION BUG IF ONLY TWO STORIES ARE ONLINE
			if(firstVisibleIndex > 0) {
				$('.story').eq(firstVisibleIndex - 1).css({
					top : -scrollOffset - windowHeight
				});
			}
			$('.story').eq(firstVisibleIndex + 2).css({
				top : -scrollOffset + 2 * windowHeight
			});

			$('.ie8 .article_bag, .ie7 .article_bag').css('filter', '');
		},
		updateParallaxUrl : function() {
			if(currentColumn == 'middle') {
				$('.story').each(function() {
					var imgUrl = $(this).css('background-image');
					if(imgUrl == 'none') {
						imgUrl = 'url(' + $(this).attr('data-src') + ')';

					}
					imgUrl = imgUrl.replace(/type=custom&w=[\d]*/g, redaxoImgType);

					$(this).css('background-image', imgUrl);
				});

				$('#fake_scroller').css({
					height : $('.story').size() * windowHeight
				});
			}
			if(currentColumn == 'right') {
				var storyWrapperHeight = 0;
				$('.parallax_bg').each(function() {
					var imgUrl = $(this).css('background-image');
					if(imgUrl == 'none') {
						imgUrl = 'url(' + $(this).attr('data-src') + ')';
					}
					imgUrl = imgUrl.replace(/type=custom&w=[\d]*/g, redaxoImgType);
					$(this).css('background-image', imgUrl);
					var thisHeight = redaxoCurrentImgWidth / $(this).attr('data-ratio') * 0.8;
					$(this).css('height', Math.floor(thisHeight));
					storyWrapperHeight += Math.floor(thisHeight);
				});
				$('img.parallax_item').each(function() {
					var imgUrl = $(this).attr('src');
					if(imgUrl === undefined) {
						imgUrl = $(this).attr('data-src');
					}
					imgUrl = imgUrl.replace(/type=customasset&w=[\d]*/g, redaxoImgType.replace('custom', 'customasset'));
					$(this).attr('src', imgUrl);
				});
				$('#fake_scroller').css('height', storyWrapperHeight);

				if(!Modernizr.touch) {
					ggl.updateStoryOnScroll();
				}
			}

		},
		resize : function() {
			windowHeight = $(window).height();
			windowWidth = $(window).width();
			if(currentColumn == 'middle') {
				$('.story').css({
					'height' : windowHeight
				});
				$('#fake_scroller').css('height', windowHeight * $('.story').size());
			}

			if($('#header').css('width') != '100%') {
				//$('#header').css('width', $(window).width() - scrollbarWidth());
			}
			
			if(windowWidth<600){
				$(".touch #the_stories_heading, .touch #the_bags_heading").css({
					width: windowWidth-30
				});
			}else{
				$(".touch #the_stories_heading, .touch #the_bags_heading").css({
					width: "80%"
				});
			}

			$(window).scrollTop($(window).scrollTop() + 1);

			if(Modernizr.touch && windowWidth <= 600) {
				//$('.storefinder_block, .storefinder_separator').css('width', '');
			} else {
				$('.storefinder_block, .storefinder_separator').css('width', windowWidth - scrollbarWidth() - 92);
			}

			var mapWidth = 910;
			if(windowWidth - scrollbarWidth() - 427 < 910) {
				mapWidth = windowWidth - scrollbarWidth() - 427;
			}
			$('#storefinder_store_right_column').css('width', mapWidth);

			var referenceW = 0;
			var oldRedaxoImgWidth = redaxoCurrentImgWidth;
			// DEFINE IMG TYPES HERE
			if(windowWidth / windowHeight < storyImgRatio && currentColumn == 'middle') {
				referenceW = windowHeight * storyImgRatio;
				if(navigator.userAgent.match(/iPad/i)) {
					// PREVENT iPAD FROM DOWNSIZING IMAGES IN PORTRAIT MODE AUTOMATICALLY
					if(referenceW > 1700) {
						referenceW = 1699;
					}
				}
			} else {
				referenceW = windowWidth;
			}
			
			if(referenceW > 2000) {
				redaxoCurrentImgWidth = 2400;
			}else if(referenceW > 1700) {
				redaxoCurrentImgWidth = 2000;
			} else if(referenceW > 1450) {
				redaxoCurrentImgWidth = 1700;
			} else if(referenceW > 1024) {
				redaxoCurrentImgWidth = 1450;
			} else if(referenceW > 900) {
				redaxoCurrentImgWidth = 1024;
			} else if(referenceW > 768) {
				redaxoCurrentImgWidth = 900;
			} else if(referenceW > 480) {
				redaxoCurrentImgWidth = 768;
			} else {
				redaxoCurrentImgWidth = 480;
			}
			redaxoImgType = 'type=custom&w=' + redaxoCurrentImgWidth;
			if(oldRedaxoImgWidth != redaxoCurrentImgWidth) {
				ggl.updateParallaxUrl();
			}

			if(windowWidth > 1450) {
				$('.bag_thumb, .storie_thumb').each(function(index) {
					var newW = 0;
					if(index % 6 == 5) {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 6);
						$(this).css({
							'width' : windowWidth - scrollbarWidth() - 5 * newW,
							'height' : newW
						});
					} else {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 6);
						$(this).css({
							'width' : newW,
							'height' : newW
						});
					}

				});
			} else if(windowWidth <= 1450 && windowWidth > 1100) {
				$('.bag_thumb, .storie_thumb').each(function(index) {
					var newW = 0;
					if(index % 5 == 4) {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 5);
						$(this).css({
							'width' : windowWidth - scrollbarWidth() - 4 * newW,
							'height' : newW
						});
					} else {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 5);
						$(this).css({
							'width' : newW,
							'height' : newW
						});
					}

				});
			} else if(windowWidth <= 1100 && windowWidth > 920) {
				$('.bag_thumb, .storie_thumb').each(function(index) {
					var newW = 0;
					if(index % 4 == 3) {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 4);
						$(this).css({
							'width' : windowWidth - scrollbarWidth() - 3 * newW,
							'height' : newW
						});
					} else {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 4);
						$(this).css({
							'width' : newW,
							'height' : newW
						});
					}
				});
			} else if(windowWidth <= 920 && windowWidth > 650) {
				$('.bag_thumb, .storie_thumb').each(function(index) {
					var newW = 0;
					if(index % 3 == 2) {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 3);
						$(this).css({
							'width' : windowWidth - scrollbarWidth() - 2 * newW,
							'height' : newW
						});
					} else {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 3);
						$(this).css({
							'width' : newW,
							'height' : newW
						});
					}
				});
			} else if(windowWidth <= 650) {
				$('.bag_thumb, .storie_thumb').each(function(index) {
					var newW = 0;
					if(index % 2 == 1) {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 2);
						$(this).css({
							'width' : windowWidth - scrollbarWidth() - newW,
							'height' : newW
						});
					} else {
						newW = Math.floor((windowWidth - scrollbarWidth()) / 2);
						$(this).css({
							'width' : newW,
							'height' : newW
						});
					}
				});
			}
		},
		ende : 'ende'
	};
}(this));


var archive = ( function(win) {
	var lastSaisonLoaded = 0,
		archiveSaison = new Array(),
		loadingMore = false;
	return {
		init : function(){
			$(".archive_line_link").live("click", function(){
				$(this).parent().find(".archive_line_link").removeClass("active").css("color","#fff");
				var activeColor = $(this).parent().attr("data-activecolor");
				$(this).addClass("active").css("color",activeColor);
				var thisSaisonIndex = $(".archive_saison").index($(this).parent().parent().parent());
				var thisLineIndex = $(this).parent().find('li').index($(this));		
				setTimeout(function() {
					archive.loadArchiveLineModels(thisSaisonIndex, thisLineIndex, 0);
				},400);					
			});
			
			$(".archive_line_thumb").live("click", function(){				
				var thisSaisonIndex = $(".archive_saison").index($(this).parent().parent().parent());
				var thisLineIndex = $(this).parent().find('.archive_line_thumb').index($(this));
				var activeColor = $(this).parent().parent().find(".archive_saison_menu").attr("data-activecolor");				
				$(this).parent().parent().find("li").eq(thisLineIndex).addClass("active").css("color",activeColor);
				
				setTimeout(function() {
					archive.loadArchiveLineModels(thisSaisonIndex, thisLineIndex, 0);
				},400);					
			});
			
			$(".archive_line_model").live("click", function(){				
				var thisSaisonIndex = $(".archive_saison").index($(this).parent().parent().parent());
				var thisLineIndex = $(this).attr("data-lineindex");		
				var modelIndex = $(this).parent().find(".archive_line_model").index($(this));
				setTimeout(function() {
					archive.loadArchiveLineColors(thisSaisonIndex, thisLineIndex, modelIndex);
				},400);					
			});
			
			$(".archive_line_color").live("click", function(){				
				var thisSaisonIndex = $(".archive_saison").index($(this).parent().parent().parent());
				var thisLineIndex = $(this).attr("data-lineindex");		
				var colorIndex = $(this).parent().find(".archive_line_color").index($(this));
				setTimeout(function() {
					archive.loadArchiveLineModels(thisSaisonIndex, thisLineIndex, colorIndex);
				},400);					
			});
			
			$("#scroller_archive").scroll(function(){
				var scrollTop = $("#scroller_archive").scrollTop();
				
				var archiveHeight = 0;
				$(".archive_saison").each(function() {
					if($(this).css("display") === "block"){
						archiveHeight += $(this).height();	
					}					
				});
				if(scrollTop>= archiveHeight - $(window).height() - 2 && !loadingMore){
					loadingMore = true;
					archive.loadMoreSaisons();
				}				
			});
			
					
		},
		loadArchiveLineModels : function(saisonIndex, lineIndex, colorIndex){		
			var selectedLineModels = archiveSaison[saisonIndex][lineIndex].models;
			var selectedLineColors = archiveSaison[saisonIndex][lineIndex].colors;
			var saisonPrefix = archiveSaison[saisonIndex][lineIndex].saisonPrefix;
			var lineName = archiveSaison[saisonIndex][lineIndex].lineName;
			
			var thisColor = selectedLineColors[colorIndex].id;
			var thisColorName = selectedLineColors[colorIndex].name;
			
			$(".archive_saison_thumb_list").eq(saisonIndex).empty();
			
			var listMarkup = "";
			for(var i=0, len = selectedLineModels.length; i<len; i++){
				var thisModel = selectedLineModels[i].src;
				var thisModelName = selectedLineModels[i].name;
				listMarkup += ''
				+'<div class="archive_thumb archive_line_model" data-lineindex="'+lineIndex+'">'
					+'<div class="thumbLoading"></div>'
					+'<img src="'+ saisonPrefix + thisModel.replace("[[COLOR]]",thisColor) +'" alt="'+lineName+'" onerror="archive.handlerImgError(this)"/>'
					+'<div class="archive_thumb_info">'
						+'<div class="archive_thumb_model">'+thisModelName+'</div><br/>'	
						+'<div class="archive_thumb_color">'+thisColorName+'</div>'			
					+'</div>'
				+'</div>';				
			}		
			$(".archive_saison_thumb_list").eq(saisonIndex).html(listMarkup);			
			archive.preloadImgInWrapper($(".archive_saison_thumb_list").eq(saisonIndex),0);
			
			
			/*
			 * +'<div class="archive_thumb_model">'+thisFirstModelName+'</div><br/>'
							+'<div class="archive_thumb_color">'+thisFirstColorName+'</div>'
			 */
		},
		loadArchiveLineColors : function(saisonIndex, lineIndex, modelIndex){		
			var selectedLineModels = archiveSaison[saisonIndex][lineIndex].models;
			var selectedLineColors = archiveSaison[saisonIndex][lineIndex].colors;
			var saisonPrefix = archiveSaison[saisonIndex][lineIndex].saisonPrefix;
			var lineName = archiveSaison[saisonIndex][lineIndex].lineName;			
			var thisModel = selectedLineModels[modelIndex].src;			
			var thisModelName = selectedLineModels[modelIndex].name;
			
			$(".archive_saison_thumb_list").eq(saisonIndex).empty();
			
			var listMarkup = "";
			for(var i=0, len = selectedLineColors.length; i<len; i++){
				var thisColor = selectedLineColors[i].id;
				var thisColorName = selectedLineColors[i].name;
				listMarkup += ''
				+'<div class="archive_thumb archive_line_color" data-lineindex="'+lineIndex+'">'
					+'<div class="thumbLoading"></div>'
					+'<img src="'+ saisonPrefix + thisModel.replace("[[COLOR]]",thisColor) +'" alt="'+lineName+'" onerror="archive.handlerImgError(this)"/>'
					+'<div class="archive_thumb_info">'
						+'<div class="archive_thumb_model">'+thisModelName+'</div><br/>'	
						+'<div class="archive_thumb_color">'+thisColorName+'</div>'			
					+'</div>'
				+'</div>';				
			}		
			$(".archive_saison_thumb_list").eq(saisonIndex).html(listMarkup);		
			
			archive.preloadImgInWrapper($(".archive_saison_thumb_list").eq(saisonIndex),0);
		},
		handlerImgError : function(that) {
			that.src = "img/not_available.png";
		},
		preloadImgInWrapper : function($wrapper, startIndex){
			var $currentImg = $wrapper.find("img").eq(startIndex);
			if($currentImg.get(0).complete){				
				$currentImg.parent().find(".thumbLoading").remove();
				$currentImg.animate({
					opacity:1
				},{
					duration:200
				});		
				if(startIndex < $wrapper.find("img").size()-1){
					setTimeout(function(){
						archive.preloadImgInWrapper($wrapper, startIndex+1);
					},150);
				}
			}else{				
				setTimeout(function(){
					archive.preloadImgInWrapper($wrapper, startIndex);
				},100);				
			}
		},
		loadMoreSaisons : function(){
			$('.archive_saison').each(function(index){
				if(index >= lastSaisonLoaded && index < lastSaisonLoaded+3){
					$(this).css("display","block");
					var saisonLink = $(this).attr("data-lines");
					archive.loadSaison(saisonLink, $(this));
				}													
			});		
			lastSaisonLoaded += 3;	
			loadingMore = false;	
		},
		loadArchive : function(link) {
			
			lastSaisonLoaded = 0, nbSaisonsToPreload = 3,
			archiveLines = new Array();
			
			$.ajax({
				url : link,
				success : function(data) {
					var ajaxContent = $(data).filter('#ajax_content');
					$('#scroller_archive').html(ajaxContent);
					$("#ajax_title").remove();
					
					
					$(".archive_saison:first").append('<div id="archive_heading">Archive</div>');
					var imgArray = new Array();
					
					imgArray.push($(".archive_saison:eq(0)").css("background-image").replace(/\"/g, '').replace('url(', '').replace(')', '').replace(/\'/g, ''));
					imgArray.push($(".archive_saison:eq(1)").css("background-image").replace(/\"/g, '').replace('url(', '').replace(')', '').replace(/\'/g, ''));
					imgArray.push($(".archive_saison:eq(2)").css("background-image").replace(/\"/g, '').replace('url(', '').replace(')', '').replace(/\'/g, ''));
					
					ggl.preload(imgArray, function(){						
						$('.archive_saison').each(function(index){
							if(index < nbSaisonsToPreload){
								$(this).css("display","block");
								var saisonLink = $(this).attr("data-lines");
								archive.loadSaison(saisonLink, $(this));
							}													
						});		
						lastSaisonLoaded = 	nbSaisonsToPreload;		
							
						$('html').css('overflow-y', 'hidden');
					
						$('#scroller_meta').animate({
							'scrollTop' : 1
						}, {
							duration : 5
						});
						currentColumn = 'middle';
						ggl.slideOutStoryToBlogLink();
						ggl.slideOutStoryToBagsLink();
						ggl.slideOutBagsToBlogLink();
						ggl.slideOutLineToStoryLink();

						if(Modernizr.csstransforms3d && Modernizr.touch) {
							$('#columns_wrapper').removeClass('bags').removeClass('story');
						} else {
							$('#columns_wrapper').animate({
								'margin-left' : '-100%'
							}, {
								duration : 400,
								easing : 'easeOutSine'
							});
						}

						$('#meta_column').css('display', 'block').delay(100).animate({
							opacity : 1
						}, {
							duration : 400,
							complete : function() {
								$('#scroller_middle, #story_column, #bags_column').css('display', 'none');
								ggl.resetBags();
							}
						});
					});	
								
				},
				dataType : 'html'
			});
			
		},		
		loadSaison : function(xml_path, $saisonNode) {
			var xml = loadXML(xml_path);				
			var saisonPrefix = $(xml).find("lines:first").attr("url").replace("350w","100w");
			var saisonMenuMarkUp = "";
			var saisonListMarkUp = "";
			var thisSaisonColor = $saisonNode.find(".archive_saison_menu").attr("data-activecolor");
			// Create a new Array to Hold the Saison Info
			archiveSaison.push(new Array());
			
			$(xml).find('line').each(function(index){				
				var thisLineName = $(this).find("label").text();				
				var thisFirstColor = $(this).find("color:first").attr("id");
				var thisFirstModel = $(this).find("model:last").attr("src");
				var thisFirstModelName = $(this).find("model:last").text();
				var thisFirstColorName = $(this).find("color:first").text();
				
								
				// Create a new Array to Hold the info for line i of the Saison		
				archiveSaison[archiveSaison.length-1].push({lineName: thisLineName, saisonPrefix: saisonPrefix, models : new Array(), colors : new Array()});
				
				saisonMenuMarkUp += '<li class="archive_line_link">'+thisLineName+'</li>';
				saisonListMarkUp += ''
					+'<div class="archive_thumb archive_line_thumb">'
						+'<div class="thumbLoading"></div>'
						+'<img src="'+ saisonPrefix + thisFirstModel.replace("[[COLOR]]",thisFirstColor) +'" alt="'+thisLineName+'" onerror="archive.handlerImgError(this)"/>'
						+'<div class="archive_thumb_info">'
							+'<div class="archive_thumb_line" style="background:'+thisSaisonColor+'">'+thisLineName+'</div><br/>'							
						+'</div>'
					+'</div>';				
				
				$(this).find("model").each(function(){
					archiveSaison[archiveSaison.length-1][index].models.push({name: $(this).text(), src:$(this).attr("src")});					
				});
				$(this).find("color").each(function(){
					archiveSaison[archiveSaison.length-1][index].colors.push({name: $(this).text(), id:$(this).attr("id")});		
				});
			
			});
			$saisonNode.find(".archive_saison_menu").html(saisonMenuMarkUp);
			$saisonNode.find(".archive_saison_thumb_list").html(saisonListMarkUp);
			archive.preloadImgInWrapper($saisonNode.find(".archive_saison_thumb_list"),0);			
		},
		ende : 'ende'
	};
}(this));

var storefinder = ( function(win) {
	var currentfilter = 'ALL', currentArea = '0', currentCountry = '', currentCity = '', currentStore = '', autocomplete_gglStores = new Array(), autocomplete_retails = new Array();
	return {
		init : function() {

			$('#enable_storefinder_filter').live('click', function() {
				if($(this).hasClass('checked')) {
					$(this).removeClass('checked');
					currentfilter = 'ALL';
					storefinder.getAreas(currentCountry, $('.country_placeholder:first').html());
				} else {
					$(this).addClass('checked');
					currentfilter = $('#filter_dropdrown option:selected').val();
					storefinder.getAreas(currentCountry, $('.country_placeholder:first').html());
				}
			});

			$('.storefinder_map_area').live('mouseenter', function() {
				$('#storefinder_map_img').attr('src', 'img/storefinder_map_' + $(this).attr('id').replace('area_', '') + '.png');
			});
			$('.storefinder_map_area').live('mouseleave', function() {
				$('#storefinder_map_img').attr('src', $('#storefinder_map_img').attr('data-current'));
			});
			$('.storefinder_map_area').live('click', function() {
				var continent = $(this).attr('data-continent');
				var continent_name = $(this).attr('data-name');
				$('#storefinder_map_img').attr('data-current', 'img/storefinder_map_' + $(this).attr('id').replace('area_', '') + '.png');
				$('#storefinder_map_img').attr('src', $('#storefinder_map_img').attr('data-current'));
				storefinder.getCountries(continent, continent_name);
				return false;
			});
			// IPHONE STOREFINDER HIDDEN SELECTBOX

			$('#select_filter_phone_btn').live('click', function() {
				$('#filter_dropdrown').focus();
				return false;
			});

			$('#select_countinent_phone_btn').live('click', function() {
				$('#select_continent_box').focus();
				return false;
			});
			$('#select_continent_box').live('change', function() {
				var $selectedItem = $('#select_continent_box option:selected');
				var continent = $selectedItem.val();
				var continent_name = $selectedItem.html();
				$('.phone_select_btn:gt(0)').html('select');

				if(continent != "") {
					$('#select_countinent_phone_btn').html(continent_name);
					storefinder.getCountries(continent, continent_name);
				}

				return false;
			});

			$('#select_country_phone_btn').live('click', function() {
				$('#select_country_box').focus();
				return false;
			});
			$('#select_country_box').live('change', function() {
				var $selectedItem = $('#select_country_box option:selected');
				var countryID = $selectedItem.val();
				var countryName = $selectedItem.html();

				$('.phone_select_btn:gt(1)').html('select');

				if(countryID != "") {
					$('#select_country_phone_btn').html(countryName);
					currentCountry = countryID;
					storefinder.getAreas(countryID, countryName);
				}
				return false;
			});

			$('#select_areas_phone_btn').live('click', function() {
				$('#select_areas_box').focus();
				return false;
			});
			$('#select_areas_box').live('change', function() {
				var $selectedItem = $('#select_areas_box option:selected');
				var area = $selectedItem.html().trim();
				var val = $selectedItem.val();
				$('.phone_select_btn:gt(2)').html('select');

				if(val != "") {
					$('#select_areas_phone_btn').html(area);
					currentArea = area;
					storefinder.getCities(area, currentCountry);
				}
				return false;
			});

			$('#select_cities_phone_btn').live('click', function() {
				$('#select_cities_box').focus();
				return false;
			});
			$('#select_cities_box').live('change', function() {
				var $selectedItem = $('#select_cities_box option:selected');
				var city = $selectedItem.html().trim();
				var val = $selectedItem.val();
				currentCity = city;
				$('.phone_select_btn:gt(3)').html('select');

				if(val != "") {
					$('#select_cities_phone_btn').html(city);
					storefinder.getStores(currentCountry, currentArea, city);
				}
				return false;
			});

			$('#storefinder_select_country .storefinder_list_item').live('click', function() {
				$('#storefinder_select_country .storefinder_list_item').removeClass('active');
				$(this).addClass('active');
				var countryID = $(this).attr('data-id');
				var countryName = $(this).find('span').html();
				currentCountry = countryID;
				storefinder.getAreas(countryID, countryName);
				return false;
			});
			$('.storefinder_area span').live('click', function() {
				$('.storefinder_area span').removeClass('active');
				$(this).addClass('active');
				var area = $(this).html().trim();
				currentArea = area;
				storefinder.getCities(area, currentCountry);
				return false;
			});
			$('.storefinder_state span').live('click', function() {
				$('.storefinder_state span').removeClass('active');
				$(this).addClass('active');
				var state = $(this).parent().attr('data-id');
				var area = $(this).html();
				currentArea = state;
				storefinder.getCitiesByState(state, area)
				return false;
			});
			$('.storefinder_store').live('click', function() {
				$('.storefinder_store').removeClass('active');
				$(this).addClass('active');
				var storeId = $(this).attr('data-id');
				storefinder.getStore(storeId);

				return false;
			});
			$('.store_city span').live('click', function() {
				$('.store_city').removeClass('active');
				$(this).parent().addClass('active');
				var city = $(this).html().trim();
				currentCity = city;
				storefinder.getStores(currentCountry, currentArea, city);
				return false;
			});
			$('#storefinder_search').live('focus', function() {
				if($(this).val() == $(this).attr('data-placeholder')) {
					$(this).val('');
				}
			});
			$('#storefinder_search').live('blur', function() {
				if($(this).val() == '') {
					$(this).val($(this).attr('data-placeholder'));
				}

			});
			$('#storefinder_search').live('keyup', function() {
				storefinder.getResultsForAutocomplete(currentCountry, $(this).val());
			});
			$('.autocomplete_result').live('click', function() {
				setTimeout(function() {
					$("#autocomplete_results").css({
						display : 'none'
					});
					$('#storefinder_search').val($('#storefinder_search').attr('data-placeholder'));
				}, 20);
				if($(this).hasClass('autocomplete_ggl')) {
					var storeId = $(this).attr('data-id');
					$('.storefinder_block:gt(3)').css({
						'display' : 'none',
						'opacity' : 0,
						height : 0
					});
					$('.storefinder_separator:gt(3)').css({
						'display' : 'none'
					});
					storefinder.getStore(storeId);
				} else if(!$(this).hasClass('no-entries')) {

					var zip = $(this).find('.result_zip').html().trim().replace('<span class="strong">', '').replace('</span>', '');
					var city = $(this).find('.result_city').html().trim().replace('<span class="strong">', '').replace('</span>', '');
					storefinder.getStoresByZip(zip, city, currentCountry);
				}

			});
			$('#show_onlinestores').live('click', function() {
				storefinder.getOnlineStores(currentCountry);
				return false;
			});
			$('#filter_dropdrown').live('change', function() {
				var filterOption = $('#filter_dropdrown option:selected').eq(0).html();
				$('.phone_select_btn:gt(2)').html('select');
				$('#select_filter_phone_btn').html(filterOption);

				if($('#enable_storefinder_filter').hasClass('checked')) {
					currentfilter = $(this).find("option:selected").eq(0).attr('value');
					storefinder.getAreas(currentCountry, $('.country_placeholder:first').html());
				}
			});

			$('.storefinder_slideshow_thumb').live('click', function() {
				$('#storefinder_store_slideshow_current img').attr('src', $(this).attr('src'));
			});

			$('#open_vcf').live('click', function() {
				var position = $(this).position();
				if($('#send_vcf_form').css('display') == 'block') {
					$(this).html('Send (VCF)');
					$('#send_vcf_form').css('display', 'none');
					$('#vcf_status').empty();
					$('#vcf_status').empty();
					$('#vcf_email_input').val('');
				} else {
					$(this).html('Close (VCF)');
					$('#send_vcf_form').css({
						'display' : 'block',
						top : position.top + 20
					}, {
						duration : 200
					});
				}

				return false;
			});

			$('#send_vcf').live('click', function() {
				$.ajax({
					url : 'http://' + document.domain + '/en/storefinder_api?getItems=vcf&store=' + currentStore + '&email=' + $('#vcf_email_input').val(),
					success : function(xml) {
						if($(xml).find('status:first').text() * 1 === 1) {
							var position = $('#open_vcf').position();
							$('#vcf_status').html('VCF Sent');
							setTimeout(function() {
								$('#send_vcf_form').css('display', 'none');
								$('#vcf_status').empty();
								$('#open_vcf').html('Send (VCF)');
							}, 1500);
						} else {
							$('#vcf_status').html($(xml).find('errorMsg:first').text());
						}
					}
				});
				return false;
			});
		},
		setFilter : function(filter) {
			currentfilter = filter;
		},
		scrollToBottom : function() {
			var animDelay = 0;
			if(Modernizr.touch && $(window).width() < 600) {
				animDelay = 400;
			} else {

			}
			$('#scroller_meta').delay(animDelay).animate({
				scrollTop : $('#storefinder').outerHeight()
			}, {
				duration : 400
			});
			if($('#where_to_buy').css('display') == 'block') {
				$('#bags_scroller').animate({
					scrollTop : $('#where_to_buy').outerHeight() + 200
				}, {
					duration : 400
				});
			}

		},
		getWTBCountries : function(id) {
			$('.storefinder_block').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(0)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=wtbcountries&filter=' + id;
			$.ajax({
				url : url,
				success : function(xml) {
					// <country id="A"><![CDATA[Austria]]></country>
					$('#storefinder_select_country_left_results').empty();

					$('#select_country_box').html('<option selected value="">Select...</option>');

					$(xml).find("country").each(function() {
						$('#select_country_box').append('<option value="' + $(this).attr('id') + '">' + $(this).text() + '</option>');
						$('#storefinder_select_country_left_results').append('<div class="storefinder_list_item" data-id="' + $(this).attr('id') + '"><span>' + $(this).text() + '</span></div>');
					});
					$('.storefinder_separator').eq(0).css({
						'display' : 'block'
					});
					$('#storefinder_select_country').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_select_country_left').height()
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});
				}
			});
		},
		getOnlineStores : function(country) {
			$('#storefinder_cities, #storefinder_stores, #storefinder_store, #storefinder_online_store').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(3)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=onlineStores&country=' + country + '&filter=' + currentfilter;
			$.ajax({
				url : url,
				success : function(xml) {
					$('#storefinder_onlinestores_results').empty();
					var appendString = '';
					$(xml).find("store").each(function() {
						var url = $(this).attr('url');
						var label = $(this).text();
						appendString += '<div class="online_store">' + label + '<br/><a href="' + url + '" target="blank">' + url + '</a></div>'
					});
					$('#storefinder_onlinestores_results').html(appendString);

					$('#storefinder_online_store').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_onlinestores_results').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});
					storefinder.scrollToBottom();
				}
			});
		},
		getResultsForAutocomplete : function(country, query) {
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=zips&country=' + country + '&zip=' + query + '&filter=' + currentfilter;
			var gglStores = new Array();
			var retails = new Array();
			$.ajax({
				url : url,
				success : function(xml) {
					$(xml).find("store").each(function() {
						var store = {};
						store.name = $(this).find('name').text();
						store.street = $(this).find('street').text();
						store.zip = $(this).find('zip').text();
						store.city = $(this).find('city').text();
						store.id = $(this).find('id').text();
						gglStores.push(store);
					});
					$(xml).find("zip").each(function() {
						var retail = {};
						retail.zip = $(this).find('zipcode').text();
						retail.label = $(this).find('label').text();
						if(retail.label != "") {
							retails.push(retail);
						}
					});
					storefinder.updateAutocomplete(gglStores, retails, query);
				}
			});
		},
		updateAutocomplete : function(ggl, retail, query) {
			autocomplete_gglStores = ggl;
			autocomplete_retails = retail;

			$('#autocomplete_results').empty();
			var appendString = '';
			for(var i = 0, len = autocomplete_gglStores.length; i < len; i++) {
				var name = autocomplete_gglStores[i].name;
				var street = autocomplete_gglStores[i].street;
				var zip = autocomplete_gglStores[i].zip.toLowerCase().myCapitalize().replace(query, '<span class="strong">' + query + '</span>');
				var city = autocomplete_gglStores[i].city.toLowerCase().myCapitalize().replace(query, '<span class="strong">' + query + '</span>');
				var id = autocomplete_gglStores[i].id;
				appendString += '<div data-id="' + id + '" class="autocomplete_result autocomplete_ggl">' + name + '<br/>' + street + '<br/>' + zip + ' ' + city + '</div>';
			}
			for(var i = 0, len = autocomplete_retails.length; i < len; i++) {
				var zip = autocomplete_retails[i].zip.toLowerCase().myCapitalize().replace(query, '<span class="strong">' + query + '</span>');
				var city = autocomplete_retails[i].label.toLowerCase().myCapitalize().replace(query, '<span class="strong">' + query + '</span>');
				var suffixClass = '';
				if(zip * 1 == 0) {
					suffixClass = ' no-entries';
				}
				appendString += '<div class="autocomplete_result' + suffixClass + '"><span class="result_zip">' + zip + '</span> <span class="result_city">' + city + '</span></div>';
			}

			$('#autocomplete_results').css('display', 'block').html(appendString);
		},
		getStore : function(id) {
			currentStore = id;
			$('#storefinder_store').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=store&store=' + id + '&filter=ALL';
			$.ajax({
				url : url,
				success : function(xml) {
					var store_label = $(xml).find('label').text();
					var store_street = $(xml).find('street').text();
					var store_zip = $(xml).find('zip').text();
					var store_city = $(xml).find('city').text();
					var store_tel = $(xml).find('tel').text();
					var store_fax = $(xml).find('fax').text();
					var store_email = $(xml).find('email').text();
					var store_url = $(xml).find('url').text();

					var slideshowImgs = new Array();
					$(xml).find('image').each(function() {
						slideshowImgs.push($(this).text());
					});
					if(slideshowImgs.length != 0) {
						$('#storefinder_store_slideshow_current').html('<img src="' + slideshowImgs[0] + '" alt="ggl_store">');
						$('#storefinder_store_slideshow_thumbs').empty();
						for(var i = 0, len = slideshowImgs.length; i < len; i++) {
							$('#storefinder_store_slideshow_thumbs').append('<img class="storefinder_slideshow_thumb" src="' + slideshowImgs[i] + '" alt="ggl_store">');
						}
						$('#storefinder_store').css('height', 502);
					} else {
						$('#storefinder_store_slideshow_current,#storefinder_store_slideshow_thumbs').empty();
						$('#storefinder_store').css('height', 'auto');
					}

					var isGGL = $(xml).find('ggl').text() * 1;
					var store_stock = $(xml).find('stock').text();
					$('#storefinder_store_heading').html(store_label);
					$('#storefinder_store_street').html(store_street);
					if(store_tel != '') {
						$('#storefinder_store_tel').html('PHONE: <span>' + store_tel + '</span>');
					} else {
						$('#storefinder_store_tel').empty();
					}
					if(store_fax != '') {
						$('#storefinder_store_fax').html('FAX: <span>' + store_fax + '</span>');
					} else {
						$('#storefinder_store_fax').empty();
					}
					$('#storefinder_store_zip_city').html(store_zip + ' ' + store_city);
					if(store_url != '') {

						if(store_url.toLowerCase().charAt(0) == 'w') {
							store_url = 'http://' + store_url;
						}
						$('#storefinder_store_url').html('WEB:<a target="blank" href="' + store_url + '">' + store_url + '</a>');
					}
					$('#storefinder_store_stock').html(store_stock);

					if($('#storefinder_alternative_stores_results .storefinder_store').size() != 0 || $('#where_to_buy').css('display') == "none") {
						$('.storefinder_separator').eq(6).css({
							'display' : 'block'
						});
					}

					$('#storefinder_store').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_store_right_column').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});
					storefinder.updateMap(store_street, store_zip, store_city);
					storefinder.scrollToBottom();
				}
			});
		},
		updateMap : function(street, zip, city) {
			// Google API V3
			var geocoder;
			var map;
			geocoder = new google.maps.Geocoder();
			var latlng = new google.maps.LatLng(-34.397, 150.644);
			var myOptions = {
				zoom : 17,
				center : latlng,
				mapTypeId : google.maps.MapTypeId.ROADMAP
			}
			map = new google.maps.Map(document.getElementById("storefinder_store_map"), myOptions);

			var address = street + " " + zip + " " + city;
			if(geocoder) {
				geocoder.geocode({
					'address' : address
				}, function(results, status) {
					if(status == google.maps.GeocoderStatus.OK) {
						$('#storefinder_store_map').show();
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
							map : map,
							position : results[0].geometry.location
						});
					} else {
						$('#storefinder_store_map').hide();
						//alert("Geocode was not successful for the following reason: " + status);
					}
				});
			}
		},
		getStoresByZip : function(zip, city, country) {
			$('.storefinder_block:gt(4)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(4)').css({
				'display' : 'none'
			});

			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=storesByZIP&country=' + country + '&zip=' + zip + '&filter=' + currentfilter;

			$.ajax({
				url : url,
				success : function(xml) {

					$('#storefinder_stores_results').empty();
					$('.city_placeholder').html(city);
					var appendString = '';
					$(xml).find('stores').find("store").each(function() {
						var store_id = $(this).attr('id');
						var store_label = $(this).find('label').text();
						var store_street = $(this).find('street').text();
						var store_zip = $(this).find('zip').text();
						var store_city = $(this).find('city').text();
						var isGGLStore = $(this).attr('ggl_store');
						var store_distance = $(this).find('distance').text();
						appendString += '' + '<div data-id="' + store_id + '" class="storefinder_store' + ((isGGLStore * 1 > 0) ? ' gglstore' : '') + '">' + store_label + '<br/>' + store_street + '<br/>' + store_zip + ' ' + store_city + '<br/>linear distance ~' + store_distance + 'km</div>';
					});
					if(appendString == '') {
						appendString = '<span class="wtb_grey_text">Sorry! No entries found for this selection.</span>';
					}
					$('#storefinder_stores_results').append(appendString);
					appendString = '';
					$('#storefinder_alternative_stores_results').empty();
					$(xml).find('alternativeStores').find("store").each(function() {
						var store_id = $(this).attr('id');
						var store_label = $(this).find('label').text();
						var store_street = $(this).find('street').text();
						var store_zip = $(this).find('zip').text();
						var store_city = $(this).find('city').text();
						var isGGLStore = $(this).attr('ggl_store');
						var store_distance = $(this).find('distance').text();
						appendString += '' + '<div data-id="' + store_id + '" class="storefinder_store' + ((isGGLStore * 1 == 1) ? ' gglstore' : '') + '">' + store_label + '<br/>' + store_street + '<br/>' + store_zip + ' ' + store_city + '<br/>linear distance ~' + store_distance + 'km</div>';
					});
					$('#storefinder_alternative_stores_results').append(appendString);
					var selectorString = '#storefinder_stores';
					if(appendString != '') {
						selectorString += ', #storefinder_alternative_stores';
						$('.storefinder_separator:eq(5)').css({
							'display' : 'block'
						});
					}

					$('.storefinder_separator').eq(5).css({
						'display' : 'block'
					});
					$('' + selectorString).css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_stores_results').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});

					$('#autocomplete_results').animate({
						height : 0
					}, {
						duration : 300,
						complete : function() {
							$(this).css('height', 'auto').empty();
						}
					});
					storefinder.scrollToBottom();
				}
			});
		},
		getStores : function(country, area, city) {
			$('.storefinder_block:gt(4)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(5)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=stores&country=' + country + '&area=' + area + '&city=' + city + '&filter=' + currentfilter;

			$.ajax({
				url : url,
				success : function(xml) {
					$('#storefinder_stores_results').empty();
					$('.city_placeholder').html(city);
					var appendString = '';
					$(xml).find("store").each(function() {
						var store_id = $(this).attr('id');
						var store_label = $(this).find('label').text();
						var store_street = $(this).find('street').text();
						var store_zip = $(this).find('zip').text();
						var store_city = $(this).find('city').text();
						var isGGLStore = $(this).attr('ggl_store');
						appendString += '' + '<div data-id="' + store_id + '" class="storefinder_store' + ((isGGLStore * 1 > 0) ? ' gglstore' : '') + '">' + store_label + '<br/>' + store_street + '<br/>' + store_zip + ' ' + store_city + '<br/>' + '</div>';
					});
					$('#storefinder_stores_results').append(appendString);
					$('.storefinder_separator').eq(5).css({
						'display' : 'block'
					});
					$('#storefinder_stores').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_stores_results').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
							if($('html').hasClass('ie8')) {
								$(this).css('filter', '');
							}
						}
					});
					storefinder.scrollToBottom();
				},
				dataType : 'xml',
				async : false
			});
		},
		getCitiesByState : function(state, area) {
			$('.storefinder_block:gt(3)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(4)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=citiesByState&state=' + state + '&area=' + area + '&filter=' + currentfilter;

			$.ajax({
				url : url,
				success : function(xml) {
					$('#storefinder_cities_results').empty();
					$('.area_placeholder').html(area);

					$('#select_cities_box').html('<option selected value="">Select...</option>');
					$(xml).find("city").each(function() {
						$('#select_cities_box').append('<option value="' + $(this).text() + '">' + $(this).text() + '</option>');
						$('#storefinder_cities_results').append('<div class="storefinder_list_item store_city"><span>' + $(this).text() + '</span></div>');
					});
					$('.storefinder_separator').eq(4).css({
						'display' : 'block'
					});
					$('#storefinder_cities').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_cities_results').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});

					$('#storefinder_cities_results').css('width', '500px');
					var currentItemTop = 0;
					var found = false;
					var nbColumn = 0;
					var maxWidthArray = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
					var nbItems = $('#storefinder_cities_results .storefinder_list_item').size();
					$('#storefinder_cities_results .storefinder_list_item').each(function(index) {

						var pos = $(this).position();
						if(index > 0 && currentItemTop != pos.top && !found) {
							nbColumn = index;
							found = true;
						}
						if(!found && index == nbItems - 1) {
							nbColumn = index;
						}
						currentItemTop = $(this).position().top;
						var columnW = (nbColumn == 0 ) ? maxWidthArray[index] : maxWidthArray[index % nbColumn];
						if($(this).width() > columnW) {
							if(nbColumn == 0) {
								maxWidthArray[index] = $(this).width() + 5;
							} else {
								maxWidthArray[index % nbColumn] = $(this).width() + 5;
							}
						}
					});

					$('#storefinder_cities_results .storefinder_list_item').each(function(index) {
						$(this).css('width', maxWidthArray[index % nbColumn]);
					});
					var wrapperWidth = 0;
					for(var i = 0, len = maxWidthArray.length; i < len; i++) {
						if(maxWidthArray[i] != 0) {
							wrapperWidth += maxWidthArray[i] + 7;
						}
					}
					$('#storefinder_cities_results').css('width', wrapperWidth);

					storefinder.scrollToBottom();
				},
				dataType : 'xml',
				async : false
			});
		},
		getCities : function(area, country) {
			$('.storefinder_block:gt(3)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(4)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=citiesByArea&country=' + country + '&area=' + area + '&filter=' + currentfilter;

			$.ajax({
				url : url,
				success : function(xml) {
					$('#storefinder_cities_results').empty();
					$('.area_placeholder').html(area);
					$('#select_cities_box').html('<option selected value="">Select...</option>');
					$(xml).find("city").each(function() {
						$('#select_cities_box').append('<option value="' + $(this).text() + '">' + $(this).text() + '</option>');
						$('#storefinder_cities_results').append('<div class="storefinder_list_item store_city"><span>' + $(this).text() + '</span></div>');
					});
					$('.storefinder_separator').eq(4).css({
						'display' : 'block'
					});
					$('#storefinder_cities').css({
						'display' : 'block'
					}).stop().animate({
						opacity : 1,
						height : $('#storefinder_cities_results').outerHeight() + 40
					}, {
						duration : 500,
						complete : function() {
							$(this).css('height', 'auto');
						}
					});

					$('#storefinder_cities_results').css('width', '500px');
					var currentItemTop = 0;
					var found = false;
					var nbColumn = 0;
					var maxWidthArray = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
					var nbItems = $('#storefinder_cities_results .storefinder_list_item').size();
					$('#storefinder_cities_results .storefinder_list_item').each(function(index) {

						var pos = $(this).position();
						if(index > 0 && currentItemTop != pos.top && !found) {
							nbColumn = index;
							found = true;
						}
						if(!found && index == nbItems - 1) {
							nbColumn = index;
						}
						currentItemTop = $(this).position().top;
						var columnW = (nbColumn == 0 ) ? maxWidthArray[index] : maxWidthArray[index % nbColumn];
						if($(this).width() > columnW) {
							if(nbColumn == 0) {
								maxWidthArray[index] = $(this).width() + 5;
							} else {
								maxWidthArray[index % nbColumn] = $(this).width() + 5;
							}
						}
					});

					$('#storefinder_cities_results .storefinder_list_item').each(function(index) {
						$(this).css('width', maxWidthArray[index % nbColumn]);
					});
					var wrapperWidth = 0;
					for(var i = 0, len = maxWidthArray.length; i < len; i++) {
						if(maxWidthArray[i] != 0) {
							wrapperWidth += maxWidthArray[i] + 7;
						}
					}
					$('#storefinder_cities_results').css('width', wrapperWidth);

					storefinder.scrollToBottom();
				},
				dataType : 'xml',
				async : false
			});
		},
		getCountries : function(cont, cont_name) {
			$('.storefinder_block:gt(0)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(1)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=countries&continent=' + cont;
			currentfilter = 'ALL';

			$.ajax({
				url : url,
				success : function(xml) {
					$('.select_country_placeholder').html(' ' + cont_name);
					storefinder.parseCountries(xml);
				},
				dataType : 'xml',
				async : false
			});
			storefinder.getFilter();
		},
		parseCountries : function(xml) {
			$('#storefinder_select_country_left_results').empty();
			$('#select_country_box').html('<option selected value="">Select...</option>');
			$(xml).find("country").each(function() {
				$('#select_country_box').append('<option value="' + $(this).attr('id') + '">' + $(this).text() + '</option>');
				$('#storefinder_select_country_left_results').append('<div class="storefinder_list_item" data-id="' + $(this).attr('id') + '"><span>' + $(this).text() + '</span></div>');
			});

			$('.storefinder_separator').eq(1).css({
				'display' : 'block'
			});
			$('#storefinder_select_country').css({
				'display' : 'block'
			}).stop().animate({
				opacity : 1,
				height : $('#storefinder_select_country_left').height()
			}, {
				duration : 500,
				complete : function() {
					$(this).css('height', 'auto');

				}
			});
			$('#storefinder_select_country_left').css('width', '500px');
			var currentItemTop = 0;
			var found = false;
			var nbColumn = 0;
			var maxWidthArray = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
			var nbItems = $('#storefinder_select_country_left_results .storefinder_list_item').size();
			$('#storefinder_select_country_left_results .storefinder_list_item').each(function(index) {

				var pos = $(this).position();
				if(index > 0 && currentItemTop != pos.top && !found) {
					nbColumn = index;
					found = true;
				}
				if(!found && index == nbItems - 1) {
					nbColumn = index;
				}
				currentItemTop = $(this).position().top;

				var columnW = (nbColumn == 0 ) ? maxWidthArray[index] : maxWidthArray[index % nbColumn];
				if($(this).width() > columnW) {
					if(nbColumn == 0) {
						maxWidthArray[index] = $(this).width() + 5;
					} else {
						maxWidthArray[index % nbColumn] = $(this).width() + 5;
					}
				}
			});

			$('#storefinder_select_country_left_results .storefinder_list_item').each(function(index) {
				$(this).css('width', maxWidthArray[index % nbColumn]);
			});
			var wrapperWidth = 0;
			for(var i = 0, len = maxWidthArray.length; i < len; i++) {
				if(maxWidthArray[i] != 0) {
					wrapperWidth += maxWidthArray[i] + 7;
				}
			}
			$('#storefinder_select_country_left').css('width', wrapperWidth);
			storefinder.scrollToBottom();
		},
		getFilter : function() {
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=filterContent';
			$.ajax({
				url : url,
				success : function(xml) {
					$('#filter_dropdrown').empty();
					$(xml).find("entry").each(function() {
						//$('#filter_dropdrown').append('<option value="' +  + '">' + + '</option>');
						$('#filter_dropdrown').append($('<option>', {
							value : $(this).attr('id')
						}).text($(this).text()));
					});
				},
				dataType : 'xml',
				async : false
			});
		},
		getAreas : function(country, countryName) {
			$('.storefinder_block:gt(1)').css({
				'display' : 'none',
				'opacity' : 0,
				height : 0
			});
			$('.storefinder_separator:gt(1)').css({
				'display' : 'none'
			});
			var url = 'http://' + document.domain + '/en/storefinder_api?getItems=areas&country=' + country + '&filter=' + currentfilter;

			$.ajax({
				url : url,
				success : function(xml) {
					storefinder.parseAreas(xml);
					$('.country_placeholder').html(countryName);
				},
				dataType : 'xml',
				async : false
			});
		},
		parseAreas : function(xml) {
			$('#storefinder_areas_results, #storefinder_states_results').empty();
			$('#select_areas_box').html('<option selected value="">Select...</option>');
			$(xml).find("area").each(function() {
				if($(this).text() != '') {
					$('#select_areas_box').append('<option value="' + $(this).text() + '">' + $(this).text() + '</option>');
					$('#storefinder_areas_results').append('<div class="storefinder_area"><span>' + $(this).text() + '</span></div>');
				}
			});
			$(xml).find("state").each(function(index) {
				if(index == 0) {
					$('#storefinder_states').css('display', 'block');
					$('#search_zip').css('display', 'none');
				}
				$('#storefinder_states_results').append('<div class="storefinder_state" data-id="' + $(this).attr('id') + '" data-label="' + $(this).attr('label') + '"><span>' + $(this).text() + '</span></div>');
			});
			if($(xml).find("area").size() == 0) {
				$('#storefinder_areas_results').html('<span class="no_entries">Sorry no entries found.</span>');
			}

			if($(xml).find("state").size() == 0) {
				$('#storefinder_states').css('display', 'none');
				$('#search_zip').css('display', 'block');
			}
			if(currentCountry == 'DE' || currentCountry == 'CH' || currentCountry == 'A') {
				$('#search_zip').show();
			} else {
				$('#search_zip').hide();
			}

			if($(xml).find("areas:first").attr('onlineStores') == 'true') {
				$('#storefinder_online_stores').show();
			} else {
				$('#storefinder_online_stores').hide();
			}
			$('.storefinder_separator:lt(4)').not('.hidden').css({
				'display' : 'block'
			});
			$('#storefinder_areas').css({
				'display' : 'block'
			}).stop().animate({
				opacity : 1,
				height : 50
			}, {
				duration : 500,
				complete : function() {
					$(this).css('height', 'auto');
				}
			});
			$('#storefinder_filter').css({
				'display' : 'block'
			}).stop().animate({
				opacity : 1,
				height : 50
			}, {
				duration : 500,
				complete : function() {
					$(this).css('height', 'auto');
				}
			});

			storefinder.scrollToBottom();
		},
		ende : 'ende'
	};
}(this));

function scrollbarWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	scr.style.overflow = 'hidden';
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';
	scr.appendChild(inn);
	document.body.appendChild(scr);
	wNoScroll = inn.offsetWidth;
	scr.style.overflow = 'auto';
	wScroll = inn.offsetWidth;
	document.body.removeChild(document.body.lastChild);
	return (wNoScroll - wScroll);
}

function loadXML(f) {
	var json = {};
	$.ajax({
		url : f,
		success : function(xml) {
			json = xml;
		},
		dataType : 'xml',
		async : false
	});
	return json;
}

function hexToR(h) {
	return parseInt((cutHex(h)).substring(0, 2), 16)
}

function hexToG(h) {
	return parseInt((cutHex(h)).substring(2, 4), 16)
}

function hexToB(h) {
	return parseInt((cutHex(h)).substring(4, 6), 16)
}

function cutHex(h) {
	return (h.charAt(0) == "#") ? h.substring(1, 7) : h
}

function touchClass(el, name) {
	this.element = el;
	this.name = name;
	this.startX = 0;
	this.startY = 0;
	this.offsetY = 0;
	this.offsetX = 0;
	this.lastX = 0;
	this.lastY = 0;
	this.speed = 0;
	this.tempValue1 = 0;
	this.tempValue2 = 0;
	//alert('out');
	if($('html').hasClass('touch')) {

		this.element.addEventListener('touchstart', this, false);
	}

}

touchClass.prototype = {
	handleEvent : function(e) {
		switch(e.type) {
			case 'touchstart':
				this.onTouchStart(e);
				break;
			case 'touchmove':
				this.onTouchMove(e);
				break;
			case 'touchend':
				this.onTouchEnd(e);
				break;
			case 'gesturechange':
				this.onGestureChange(e);
				break;
		}
	},
	onTouchStart : function(e) {

		this.moved = false;
		$(this.element).stop();

		if(this.name == 'slideshow' || this.name == 'zoom_item') {
			e.preventDefault();
		}
		if(this.name == 'zoom_item') {
			$(this.element).css({
				'-webkit-transition' : 'none'
			});
		}
		if(this.name == 'ios4') {
			e.preventDefault();

		}

		if($('html').hasClass('touch')) {
			this.startX = e.touches[0].clientX;
			this.startY = e.touches[0].clientY;
		} else {
			this.startX = e.pageX;
			this.startY = e.pageY;
		}
		this.offsetX = 0;
		this.offsetY = 0;
		this.tempValue1 = $(this.element).attr('data-offsetX') * 1;
		this.tempValue2 = $(this.element).attr('data-offsetY') * 1;

		this.element.addEventListener('touchmove', this, false);
		this.element.addEventListener('touchend', this, false);
		this.element.addEventListener('gesturechange', this, false);

	},
	onTouchMove : function(e) {
		this.moved = true;

		if($('html').hasClass('touch')) {
			this.offsetX = e.touches[0].clientX - this.startX;
			this.offsetY = e.touches[0].clientY - this.startY;
		} else {
			this.offsetX = e.pageX - this.startX;
			this.offsetY = e.pageY - this.startY;
		}
		this.speed = e.changedTouches[0].clientY - this.lastY;
		this.lastY = e.changedTouches[0].clientY;
		this.speedX = e.changedTouches[0].clientX - this.lastX;
		this.lastX = e.changedTouches[0].clientX;

		if(this.name == 'zoom_item') {
			$(this.element).css({
				'-webkit-transform' : 'translate3d(' + (this.tempValue1 + this.offsetX) + 'px, ' + (this.tempValue2 + this.offsetY) + 'px,0)'
			});
		}
	},
	onGestureChange : function(e) {
		e.preventDefault();
	},
	onTouchEnd : function(e) {

		if(this.name == 'zoom_item') {

			$(this.element).css({
				'-webkit-transition' : 'all 0.4s ease-out'
			});
			var el = this.element;
			var endX = (this.tempValue1 + this.offsetX + this.speedX * 5);
			var endY = (this.tempValue2 + this.offsetY + this.speed * 5);
			$(this.element).attr('data-offsetX', endX);
			$(this.element).attr('data-offsetY', endY);
			setTimeout(function() {
				$('#zoom_bag').css({
					'-webkit-transform' : 'translate3d(' + endX + 'px, ' + endY + 'px,0)'
				});
			}, 5);
		}
		if(this.name == 'ios4') {
			var currentStory = Math.round($('#scroller_middle').scrollTop() / $(window).height());
			var scrollEnd = 0;
			if(this.offsetY < -40) {
				scrollEnd = (currentStory + 1) * $(window).height();
			} else if(this.offsetY > 40) {
				scrollEnd = (currentStory - 1) * $(window).height();
			}

			$('#scroller_middle').stop().animate({
				scrollTop : scrollEnd
			}, {
				duration : 800,
				easing : 'easeOutSine'
			});
		}

		if(this.name == 'middle') {
			var currentStory = Math.round($(this.element).scrollTop() / $(window).height());
			var scrollEnd = 0;

			if(Math.abs(this.speed) < 4 && (Math.abs($(this.element).scrollTop() % $(window).height()) < 150 || Math.abs($(this.element).scrollTop() % $(window).height()) > $(window).height() - 150)) {
				scrollEnd = currentStory * $(window).height();
				$(this.element).stop().animate({
					scrollTop : scrollEnd
				}, {
					duration : 400,
					easing : 'easeOutSine'
				});
			} else if(Math.abs(this.speed) > 4) {
				if(this.speed < 0 && currentStory < $('.story').size()) {
					currentStory = Math.ceil($(this.element).scrollTop() / $(window).height());
				} else if(this.speed > 0) {
					currentStory = Math.floor($(this.element).scrollTop() / $(window).height());
				}
				scrollEnd = currentStory * $(window).height();
				$(this.element).stop().animate({
					scrollTop : scrollEnd
				}, {
					duration : 800,
					easing : 'easeOutSine'
				});
			}
		}
		if(this.name == 'slideshow') {
			if(this.offsetY > 40 && Math.abs(this.offsetX) < 40) {
				ggl.changeBag('previousColor');
			} else if(this.offsetY < -40 && Math.abs(this.offsetX) < 40) {
				ggl.changeBag('nextColor');
			}
			if(this.offsetX > 40 && Math.abs(this.offsetY) < 40) {
				ggl.changeBag('previousBag');
			} else if(this.offsetX < -40 && Math.abs(this.offsetY) < 40) {
				ggl.changeBag('nextBag');
			}
		}
		if(this.name == 'story') {
			var scrollEnd = $(this.element).scrollTop() + this.speed * -5;

			$(this.element).stop().animate({
				scrollTop : scrollEnd
			}, {
				duration : 800,
				easing : 'easeOutSine'
			});
		}

		this.element.removeEventListener('touchmove', this, false);
		this.element.removeEventListener('touchend', this, false);

		if($('html').hasClass('touch')) {
			if(Math.abs(this.offsetX) < 10 && Math.abs(this.offsetY) < 10) {
				if(this.name == 'slideshow') {
					ggl.loadZoom();
				}
				// Place your code here or use the click simulation below
				var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
				if(theTarget.nodeType == 3)
					theTarget = theTarget.parentNode;

				var theEvent = document.createEvent('MouseEvents');
				theEvent.initEvent('click', true, true);
				theTarget.dispatchEvent(theEvent);
			}
		}
	}
};

// VIDEO PLAYER
var video = (function() {
	var myVideo, myCanvasVideo, mp4Video, oggVideo, webmVideo, currentVideo, width, height, container, videoEnded = function() {
	}, videoPaused = function() {
	}, firstCall = false, videoIsRunning = false;
	return {
		create : function(el, file, width, height) {
			container = $(el).parent();

			var uniqueId = 'video_' + String((new Date()).getTime()).replace(/\D/gi, '');
			width = width || "100%";
			height = height || "auto";

			var poster = container.children('img');

			var controls = '';

			if(poster == undefined) {
				poster = "";
			}

			if(poster.data('dimension')) {
				width = poster.width();
				height = poster.height();
			}
			myvideo = document.createElement('video');
			myvideo.setAttribute('width', width);
			myvideo.setAttribute('height', height);
			myvideo.id = uniqueId;

			if(poster.data('controls')) {
				myvideo.controls = 'controls';
			} else {
				myvideo.controls = false;
			}
			mp4Video = document.createElement('source');
			mp4Video.setAttribute('src', file + '.mp4');
			mp4Video.setAttribute('type', "video/mp4");
			oggVideo = document.createElement('source');
			oggVideo.setAttribute('src', file + '.ogv');
			oggVideo.setAttribute('type', "video/ogg");
			webmVideo = document.createElement('source');
			webmVideo.setAttribute('src', file + '.webm');
			webmVideo.setAttribute('type', "video/webm");

			myvideo.appendChild(mp4Video);
			myvideo.appendChild(webmVideo);
			myvideo.appendChild(oggVideo);

			if(!Modernizr.touch && Modernizr.csstransforms3d) {				
				myCanvasVideo = document.createElement('canvas');
				var uniqueId2 = 'canvas_' + String((new Date()).getTime()).replace(/\D/gi, '');
				myCanvasVideo.setAttribute('width', width);
				myCanvasVideo.setAttribute('height', height);
				myCanvasVideo.id = uniqueId2;
				$(myCanvasVideo).addClass('videoCanvas');
				videoCanvas.init(myCanvasVideo, width, height, el.src);
				myvideo.play();
				canvasVideoPlaying = myvideo;
				container.append(myCanvasVideo);

				container.append('<div class="video_toggle" data-player="' + uniqueId + '"></div>');
				myvideo.addEventListener('play', function() {
					videoCanvas.drawVideo(myvideo, width, height);
				}, false);

			

			} else {
				if($('html').hasClass('ie8')) {
					container.append($('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="' + width + '" height="' + height + '" id="videoplayer" align="middle">							<param name="movie" value="/files/videoplayer.swf?src=' + file + '.mp4" />							<param name="quality" value="high" />							<param name="bgcolor" value="#ffffff" />							<param name="play" value="true" />							<param name="loop" value="true" />							<param name="wmode" value="transparent" />							<param name="scale" value="showall" />							<param name="menu" value="false" />							<param name="devicefont" value="false" />							<param name="salign" value="" />							<param name="allowScriptAccess" value="sameDomain" />							<param name="allowFullScreen" value="true" />							<!--[if !IE]>-->							<object type="application/x-shockwave-flash" data="/files/videoplayer.swf?src=' + file + '.mp4" width="550" height="400">								<param name="movie" value="/files/videoplayer.swf?src=' + file + '.mp4" />								<param name="quality" value="high" />								<param name="bgcolor" value="#ffffff" />								<param name="play" value="true" />								<param name="loop" value="true" />								<param name="wmode" value="transparent" />								<param name="scale" value="showall" />								<param name="menu" value="false" />								<param name="devicefont" value="false" />								<param name="salign" value="" />								<param name="allowScriptAccess" value="sameDomain" />								<param name="allowFullScreen" value="true" />							<!--<![endif]-->								<a href="http://www.adobe.com/go/getflash">									<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />								</a>							<!--[if !IE]>-->							</object>							<!--<![endif]-->					</object>'));
				} else {
					container.append(myvideo);
					$('#' + uniqueId)[0].play();

					var videos = document.getElementsByTagName('video');
					for(var i = 0; i < videos.length; i++) {
						videos[i].pause();
					}
					currentVideo = $('#' + uniqueId)[0];
					this.setToggle();
					videoIsRunning = true;
					firstCall = true;

					currentVideo.onended = function(e) {
					}

					currentVideo.onpause = function(e) {
						if(currentVideo.paused == true) {
							videoPaused.call();
						}
					}
				}

			}

			//container.append(myIframe);

			container.css('z-index', 10000);

			$(el).css('display', 'none');

		},
		setToggle : function() {

			$('video').each(function() {
				var containment = $(this).parent();
				var thisVideo = $(containment).children('video')[0];

				$(containment).unbind('click');
				$(containment).click(function() {

					if(currentVideo == thisVideo) {
						if(videoIsRunning) {
							thisVideo.pause();
							videoIsRunning = false;
						} else {
							thisVideo.play();
							videoIsRunning = true;
						}
					} else {
						var videos = document.getElementsByTagName('video');
						for(var i = 0; i < videos.length; i++) {
							videos[i].pause();
						}
						thisVideo.play();
					}
					currentVideo = thisVideo;

					if(firstCall) {
						thisVideo.play();
						firstCall = false;
					}

					return false;
				});
			});
		},
		addEndedCallback : function(fn) {
			videoEnded = fn;
		},
		addPausedCallback : function(fn) {
			videoPaused = fn;
		},
		resetWrapper : function(el) {
			el.unbind('click');
			el.children('video').remove();
			el.children('img').css('display', ' block');
		}
	}
})();

var videoCanvas = ( function(win) {
	var canvas, ctx, cWidth, cHeight;
	return {
		init : function(el, width, height, poster) {
			canvas = el;
			canvas.width = width;
			canvas.height = height;
			ctx = canvas.getContext("2d");
			var img = new Image();
			img.onload = function() {
				ctx.drawImage(img, 0, 0);
			};
			img.src = poster;
		},
		drawVideo : function(v, w, h) {
			if(v.paused || v.ended) {
				$('.video_toggle').addClass('paused');
				return false;
			}
			if(v.readyState > 1) {
				ctx.drawImage(v, 0, 0, w, h);
			}

			setTimeout(videoCanvas.drawVideo, 20, v, w, h);
		},
		ende : 'ende'
	};
}(this));

