﻿$(document).ready(function() {		
	// removing img tags whose src attribute value does not contain 'getdoc'. used to clean the product image 
	// slideshow from images with no proper src
	//$('img[src^="?"]').each(function() { $(this).remove() })	
	$('#slideShow > img').each(function() { 		
		if($(this).attr('src').indexOf('getdoc') == -1)
		{			
			$(this).remove();
		}
	});
	
	$('a#slideShowNext').click(function(e) { e.preventDefault(); });
	$('a#slideShowPrev').click(function(e) { e.preventDefault(); });
	buildSlideshow();
});


// initialize fancybox plugin (for fullsize image viewing)
$(document).ready(function() {
	$("a.fancybox").fancybox({ 
		overlayOpacity: 0.5,
		callbackOnStart: function() {
			// pause the slideshow while fancybox is open. does not work somehow...
			$('#pictureOfTheDaySlideshow').cycle('pause');
		},
		callbackOnClose: function() {
			$('#pictureOfTheDaySlideshow').cycle('resume');
		}
	});
});


// building slideshow for the pictures of the day
$(document).ready(function() {
	$('#pictureOfTheDaySlideshow').cycle({
		fx: 'fade',
		timeout: 4000,
		speed: 300,
		pause: 1,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag)
		{
			if(options.currSlide == 0) 
			{
				//alert('start');			
			}
			// centering the image horizontally
			if($(this).width() < $(this).parent().width())
			{
				$(this).css('left', (($(this).parent().width() - $(this).width()) / 2) + 'px');
			}
		}
	});
});


// tricon flash microsite
$(document).ready(function() {		
	
	// embedding flash and hiding it
	var flashvars = {};
	flashvars.alpha = '0.6';
	flashvars.locatorLink = location.protocol +'//' +location.hostname +'/Distributors-Dealers/DealerLocator.aspx';
	var params = {};
	params.wmode = 'transparent';
	var attributes = {};
	//attributes.id = 'flashContent';
	swfobject.embedSWF('/DTSwiss/Microsite_Tricon/Tricon.swf', 'noFlashContent', '996', $(window).height(), '9.0.0', false, flashvars, params, attributes);			
	hideTriconFlash();	
	
	
	if(window.location.href.indexOf('default.aspx?tricon=1') != -1)
	{
		if(swfobject.getFlashPlayerVersion().major < 9)
		{
			// no (appropriate) flash support -> leaving tricon microsite layer invisible			
			return;
		}				
		
		// makeing the height of the flash itself and of the the flash container identical
		$('div#micrositeTricon').height($(window).height());	
		// ok, making microsite visible
		showTriconFlash();
	}
	
	
	
	/* don't show tricon flash initially any more 
	var COOKIE_NAME = 'DTSwiss_Tricon';		
	if(swfobject.getFlashPlayerVersion().major < 9 || $.cookie(COOKIE_NAME) && location.pathname.toLowerCase().indexOf('tricon-microsite') == -1)
	{
		// no (appropriate) flash support or we found our cookie -> leaving tricon microsite layer invisible			
		return;
	}					
	
	// makeing the height of the flash itself and of the the flash container identical
	$('div#micrositeTricon').height($(window).height());	
	// ok, making microsite visible
	showTriconFlash();	
			
	//setting cookie
	$.cookie(COOKIE_NAME, '1', { expires: 10, path: '/'});		
    */		
});


$(document).ready(function() {
	$('.triconStart').click(function(e) {
		e.preventDefault();
		showTriconFlash();
	});
	
	$('.triconClose').click(function(e) {
		e.preventDefault();
		hideTriconFlash();
	});		
	
	$('.flashFallback').click(function(e) {
		e.preventDefault();
		$('#flashFallbackFancy').click();				
		$('#micrositeTricon').hide();
	});
	
	$('.pictureOfTheDayStarter').click(function(e) {
		e.preventDefault();
		$('div.pictureOfTheDay .teaser a').click()
	});	
});


// tricon flash banner
$(document).ready(function() {					
	// embedding the tricon flash teaser
	var flashvars = {};	
	var params = {};
	params.wmode = 'transparent';
	var attributes = {};
	//attributes.id = 'triconBanner';
	swfobject.embedSWF('/DTSwiss/Microsite_Tricon/teaser.swf', 'noFlashBannerFallback', '242', '200', '9.0.0', false, flashvars, params, attributes);	
});


function showTriconFlash()
{		
	if(swfobject.getFlashPlayerVersion().major < 9)
	{				
		// no (appropriate) flash support
		// creating fancybox for fallback picture and display it
		//$('a.flashFallback').each(function() { $(this).fancybox({ 'overlayOpacity': 0.5, 'imageScale': false, 'centerOnScroll': false, 'callbackOnShow': addDownloadLink } ) }); 		
		//$('#noFlashBannerFallback').hide();
		$('#flashFallbackFancy').fancybox({ 'overlayOpacity': 0.5, 'imageScale': false, 'centerOnScroll': false, 'callbackOnShow': addDownloadLink } );	
		//$('#flashFallbackFancy').click();		
		//item.click();
		$('#micrositeTricon').hide();
	}
	else
	{				
		$('#triconBannerContainer').hide();
		$('#micrositeTricon').show();
	}		
}


function hideTriconFlash()
{
	$('#triconBannerContainer').show();
	$('#micrositeTricon').hide();
}


function addDownloadLink()
{	
	// adding downloadlink to fallback picture
	$('#fancy_content').append("<a href='http://www.adobe.com/go/getflashplayer' target='_blank' style='position: absolute; height: 39px; width: 158px; z-index: 100; left: 258px; top: 381px;display:block;' class='getFlash'><img src='/resources/getflash.jpg' /></a>");
	$('.getFlash').click(function(e) {
			e.preventDefault();
			window.open(this.href);
	});		
}


function buildSlideshow() {
    
    $('#slideShow').hide();
    $('.slideShowNav').hide();
	
	if($('#slideShow img').size() == 1)
	{
	    $('#slideShow').show();
		$('#slideShow img').show();
	}
	else if($('#slideShow img').size() > 1) {
	    $('#slideShow').show();
		$('.slideShowNav').show();
		$('#slideShow').cycle({
    			fx:     'fade',
    			speed:  400,
    			timeout: 0,
    			nowrap: true,
    			fit: 0,
    			height: '520px',
    			next:   '#slideShowNext',
    			prev:   '#slideShowPrev',
			after: function(curr, next, opts) {
				// uncomment this to enable disable prev next links on first resp. last image
				//$('#slideShowPrev')[opts.currSlide == 0 ? 'hide' : 'show']();
				//$('#slideShowNext')[opts.currSlide == opts.slideCount - 1 ? 'hide' : 'show']();

				if(opts.currSlide == 0) {
					$('#slideShowPrev').removeClass('slideShowPrev');
					$('#slideShowPrev').addClass('slideShowPrevDisabled');
				}
				else {
					$('#slideShowPrev').removeClass('slideShowPrevDisabled');
					$('#slideShowPrev').addClass('slideShowPrev');
				}
				
				if(opts.currSlide == opts.slideCount - 1) {
					$('#slideShowNext').removeClass('slideShowNext');
					$('#slideShowNext').addClass('slideShowNextDisabled');
				}
				else {
					$('#slideShowNext').removeClass('slideShowNextDisabled');
					$('#slideShowNext').addClass('slideShowNext');
				}
				$('#slideShowPage').html( (opts.currSlide + 1) + '/' + opts.slideCount);
			}	
		});
	}
}