﻿$(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 } );
});


// tricon flash microsite
$(document).ready(function() {

	// embedding flash and hiding it
	var flashvars = {};
	flashvars.dataSrc = "/resources/triconData.xml";
	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);
			}	
		});
	}
}

// flyout top nav
$(document).ready(function() {
    // inital setup
    $("#topmenu").css("z-index", "0");
    $("#topmenu>li>a ").css("z-index", "2");
    // show on mouseenter
    $("#topmenu>li>a").mouseenter(function() {
        $("#topmenu a")
            .next()
            .hide();
        $(this)
            .css("z-index", "10")
            .next()
                .show();
    });
    $("#topmenu li ul").mouseenter(function() {
        $(this).prev()
            .css("z-index", "10")
            .addClass("siblingHovered");
    });
    // hide on mouse leave
    $("#topmenu").mouseleave(function() {
        $("#topmenu li ul").hide();
    });
    $("#topmenu li ul").mouseleave(function() {
        $(this).hide();
        $(this).prev()
            .removeClass("siblingHovered")
            .css("z-index", "1");
    });
    $("#topmenu>li>a").mouseleave(function() {
        $(this).css("z-index", "1");
    });
});


// flyout top nav
$(document).ready(function() {
    $("#topmenu>li>a").each(function(index) {
        var newimg = document.createElement('img');
        if ($(this).hasClass('highlighted')) {
            newimg.setAttribute('src', '/DTSwiss/GetRenderedText.aspx?text=' + encodeURIComponent($(this).text().toUpperCase()) + '&color=e91d16&bgcolor=2f2f2f&fontname=Frutiger BQ&fontsize=12&fontstyle=Bold');
        }
        else {
            newimg.setAttribute('src', '/DTSwiss/GetRenderedText.aspx?text=' + encodeURIComponent($(this).text().toUpperCase()) + '&color=d4d4d4&bgcolor=2f2f2f&fontname=Frutiger BQ&fontsize=12&fontstyle=Bold');
        }
        $(this).text('');
        $(this).append(newimg);
    });
});
