/*
CSS Browser Selector v0.3.1
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


/*======================================================================================
 CSS Psudo Class Creator
 Created: MCS - 03/17/2009
======================================================================================*/


var trigma_header = { 
  locale : null,
  
	// Handles default text input functionality
	add_hover: function(){
		$('li').hover(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		);
	},
	add_selected_nodrop: function(){
		$('#trigma_header li.selected.nodrop').addClass('selected_nodrop');
	},
	add_last: function(){
		$("#trigma_header ul").each(
			function() { 
				$(this).find("li:last").addClass('last');
			}
		);
	},
	email_form: function(){
		$("#trigma_main_subscribe").submit(
			function() {	
				location.href='https://www.trigma.com/profiles/new?';
				return false;
			}
		);
	},

	header_animate: function(){
		$('#nav li').hover(
			function() {
				trigma_header.navExpand(this);
			},
			function() {
				trigma_header.navCollapse(this);
			}
		);
		$('#nav li.main').hover(
			function() {
				$('#ishim').show();
			},
			function() {
				$('#ishim').hide();
			}
		);
		$('#nav1 li').hover(
			function() {
				trigma_header.navExpand(this);
			},
			function() {
				trigma_header.navCollapse(this);
			}
		);
		$('#nav1 li.main1').hover(
			function() {
				$('#ishim').show();
			},
			function() {
				$('#ishim').hide();
			}
		);
		
		$('#nav2 li').hover(
			function() {
				trigma_header.navExpand(this);
			},
			function() {
				trigma_header.navCollapse(this);
			}
		);
		$('#nav2 li.main2').hover(
			function() {
				$('#ishim').show();
			},
			function() {
				$('#ishim').hide();
			}
		);
		
		$('#lang li').hover(
			function() {
				trigma_header.navExpand(this);
			},
			function() {
				trigma_header.navCollapse(this);
			}
		);
		

	},
	navExpand: function(el){
		$(el).children('ul').stop().css("visibility", "visible").animate({
			height: "700px"
		},{queue:false, duration:500});
	},
	navCollapse: function(el){
		$(el).children('ul').stop().animate({
			height: "0px"
		},{queue:false, duration:10}, 'linear', $(el).children('ul').css("visibility", "hidden"));
	},
	
	
	product_list_click: function(){
		
		$('.product_list li').bind('click', function(event){
				theLink = $(this).find("a");
				
				if (theLink.attr("class") == "thickbox") {
					tb_show("Product Modal",theLink.attr("href"),false);
				} else {				  	
					//if the target started on the image - let the trigma_global.popout_handler function take over
					if(event.target.tagName != 'IMG'){
						window.open(theLink.attr("href"), '_parent')
					}
				};
		});
				
	},
	
	init:function(){
		trigma_header.add_selected_nodrop();
		trigma_header.add_hover();
		trigma_header.add_last();
		trigma_header.email_form();
		trigma_header.header_animate();
		trigma_header.product_list_click();
	}
}


/*======================================================================================
 Global JS handler
 Created: DM - 03/10/2009
======================================================================================*/


//======================================================================================
// Handles trigma Form field functionality
//======================================================================================
trigma_forms = { 
	// Handles default text input functionality
	manage_default_input: function(id){
		inpt = $(id);
		val = inpt.val();
		if(inpt){ inpt.val('').blur(function(){ if(inpt.val() != val && inpt.val() != ''){  }else{ inpt.val(val) } }) }
	},
	catalog_selects: function(){
		if($('#catalog_header')){
			$('#catalog_header div.foo:first').hover(function(){
				$(this).children('div').children('.NFSelectRight').css({ 'background-position' : '100% -56px', 'color' : '#fff' })
				$(this).children('div').children('.NFSelectLeft').css({ 'background-position' : '100% -56px' })
			},function(){
				$(this).children('div').children('.NFSelectRight').css({ 'background-position' : '100% 0', 'color' : '#666' })
				$(this).children('div').children('.NFSelectLeft').css({ 'background-position' : '100% 0' })
			});
		}
	},
	init:function(){
		$('#trigma_main_subscribe_email, #s').focus(function(){ trigma_forms.manage_default_input(this) });
		trigma_forms.catalog_selects();
	}
}

//======================================================================================
// Functions applied on every page Globally
//======================================================================================
trigma_global = { 
	// Handles "XHTML Strict" validation and lack of target="_new" support
	popout_handler: function(){
		$('a[rel="popout"]').each(function(){
			if(this.href != null && $(this).attr('rel') == 'popout' && this.href.indexOf('shop')<0 && this.href.indexOf('store')<0 ){ this.target = '_blank';  }
		});
	},
	ie_flicker_fix: function(){
		try {
			document.execCommand('BackgroundImageCache', false, true);
		} catch(e) {}
	},
	init: function(){
		trigma_global.popout_handler();
		trigma_global.ie_flicker_fix();
		// trigma_global.css_browser_selector(navigator.userAgent);
	}
}



var trigma_tracking = {
    storeUrls : new Array(
        "shop-eu.trigma.com", 
        "shop.trigma.ca", 
        "shop.trigma.fr", 
        "shop.trigma.ch", 
        "shop.trigma.de", 
        "shop.trigma.com"
    ),    
    
    track_omniture_click : function(productId, section, description) {
        var s = s_gi('trigmacom');
        s.linkTrackVars='products,events';
        s.linkTrackEvents='prodView';
        s.events='prodView';
        s.products=';' + productId;
        s.tl(true,'e',description);
	},
	
	is_store_url : function(url) {
	    var store_url = false;
	    for(i in trigma_tracking.storeUrls) {
	        if(url.indexOf(trigma_tracking.storeUrls[i]) != -1) {
	            store_url = true;
	        }
	    }
	    return store_url;
	},
	
	get_url_host : function(href) {
	    return href.split(/\/+/g)[1].split(/\?+/g)[0].replace("www.","");
	},
	
	get_product_id : function(str) {
	    var id_split = str.split("_");
	    if(id_split[2]) { return id_split[2]; }
	    return "";
	},
	
	track_header : function() {
	    // Shop Online
	    $('#trigma_header ul#nav li#nav-online-store a').click(function() {
            var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
            s.linkTrackEvents='event3';
            s.events='event3';
            s.prop11=trigma_tracking.get_url_host($(this).attr('href'));
            s.eVar7=trigma_tracking.get_url_host($(this).attr('href'));
            s.prop12='header';
            s.eVar8='header';
            s.tl(true,'e','click to store | header');
	    });
	    
	    // Find a Store
	    $('#trigma_header ul#nav li#nav-find-store a').click(function() {
	        var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop12,eVar8';
            s.linkTrackEvents='event4';
            s.events='event4';
            s.prop12='header';
            s.eVar8='header';
            s.tl(true,'e','click to find a store | header');
	    }); 
	},
	
	track_dropdown : function() {
	    // Shop Online
	    $('#trigma_header ul#nav li.main li#dropdown-online-store a').click(function() {
            var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
            s.linkTrackEvents='event3';
            s.events='event3';
            s.prop11=trigma_tracking.get_url_host($(this).attr('href'));
            s.eVar7=trigma_tracking.get_url_host($(this).attr('href'));
            s.prop12='drop down nav';
            s.eVar8='drop down nav';
            s.tl(true,'e','click to store | drop down nav');
	    });
	    
	    // Find a Store
	    $('#trigma_header ul#nav li.main li#dropdown-find-store a').click(function() {
	        var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop12,eVar8';
            s.linkTrackEvents='event4';
            s.events='event4';
            s.prop12='drop down nav';
            s.eVar8='drop down nav';
            s.tl(true,'e','click to find a store | drop down nav');
	    });
	},
	
	track_footer : function() {
        $('#trigma_footer li.store a').click(function() {
            var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
            s.linkTrackEvents='event3';
            s.events='event3';
            s.prop11=trigma_tracking.get_url_host($(this).attr('href'));
            s.eVar7=trigma_tracking.get_url_host($(this).attr('href'));
            s.prop12='footer';
            s.eVar8='footer';
            s.tl(true,'e','click to store | footer');
        });
        
        $('#trigma_footer li.findastore a').click(function() {
            var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop12,eVar8';
            s.linkTrackEvents='event4';
            s.events='event4';
            s.prop12='footer';
            s.eVar8='footer';
            s.tl(true,'e','click to find a store | footer');
        });
	},
	
	track_static_feature_button : function() {
	    $('#trigma_home #static_feature a#onlineStore').click(function() {
    	    var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
            s.linkTrackEvents='event3';
            s.events='event3';
            s.prop11=trigma_tracking.get_url_host($(this).attr('href'));
            s.eVar7=trigma_tracking.get_url_host($(this).attr('href'));
            s.prop12='static feature button';
            s.eVar8='static feature button';
            s.tl(true,'e','click to store | static feature button');
        });
        
        $('#trigma_home #static_feature a#findStore').click(function() {
            var s = s_gi('trigmacom');
            s.linkTrackVars='events,prop12,eVar8';
            s.linkTrackEvents='event4';
            s.events='event4';
            s.prop12='static feature button';
            s.eVar8='static feature button';
            s.tl(true,'e','click to find a store | static feature button');
        });
	},
	
	track_product_list : function() {
		// Homepage "Hot Stuff" section - Direct to product
	    $('#trigma_home ul.product_list li').click(function() {
	        var linkElement = $(this).find("a");
	        
	        if (linkElement.attr("class") != "thickbox") { // not opening a modal window
	            var productId = trigma_tracking.get_product_id($(this).attr("id"));
                var s = s_gi('trigmacom');
                s.linkTrackVars='events,prop11,eVar7,prop12,eVar8,products';
                s.linkTrackEvents='event3,prodView';
                s.events='event3';
                s.prop11=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.eVar7=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.products=";" + productId;
                s.prop12='hotstuff';
                s.eVar8='hotstuff';
                s.tl(true,'e','click to store | hot stuff catalog');
            }
	    }); 
	    
	    // Product Catalog *Product List*
		$('#trigma_catalog .product_list li').click(function() {
	        var linkElement = $(this).find("a");
	        
	        if (linkElement.attr("class") != "thickbox") { // not opening a modal window
	            var productId = trigma_tracking.get_product_id($(this).attr("id"));
                var s = s_gi('trigmacom');
                s.linkTrackVars='events,prop11,eVar7,prop12,eVar8,products';
                s.linkTrackEvents='event3,prodView';
                s.events='event3';
                s.prop11=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.eVar7=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.products=";" + productId;
                s.prop12='product catalog';
                s.eVar8='product catalog';
                s.tl(true,'e','click to store | product catalog');
            }
		});
		
		// Product Catalog Popup *Product "Buy Online" link*
		$('#product #product_buylinks li').click(function() {
	        var linkElement = $(this).find("a");
	        
	        if (linkElement.attr("class") != "thickbox") { // not opening a modal window
	            var productId = trigma_tracking.get_product_id($(this).attr("id"));
                var s = s_gi('trigmacom');
                s.linkTrackVars='events,prop11,eVar7,prop12,eVar8,products';
                s.linkTrackEvents='event3,prodView';
                s.events='event3';
                s.prop11=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.eVar7=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.products=";" + productId;
                s.prop12='product catalog';
                s.eVar8='product catalog';
                s.tl(true,'e','click to store | product catalog product popup');
            }
		});	
	},
	
	track_feature_panels : function() {
	    $('#trigma_home #trigma_features ul#feature_panes li').click(function() {
	        var linkElement = $(this).find('a');
	        if(trigma_tracking.is_store_url(linkElement.attr('href'))) {
                var s = s_gi('trigmacom');
                s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
                s.linkTrackEvents='event3';
                s.events='event3';
                s.prop11='';
                s.eVar7=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.prop12='feature panel';
                s.eVar8='feature panel';
                s.tl(true,'e','click to store | feature panel');
            }
	    });
	},
	
	track_feature_buttons : function() {
	    $('#trigma_home ul#features_list li').click(function() {
	        var linkElement = $(this).find('a');
	        if(trigma_tracking.is_store_url(linkElement.attr('href'))) {
    	        var s = s_gi('trigmacom');
                s.linkTrackVars='events,prop11,eVar7,prop12,eVar8';
                s.linkTrackEvents='event3';
                s.events='event3';
                s.prop11=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.eVar7=trigma_tracking.get_url_host(linkElement.attr('href'));
                s.prop12='feature button';
                s.eVar8='feature button';
                s.tl(true,'e','click to store | feature button');
            }
	    });
	},
			
    init : function() {
        trigma_tracking.track_header(); // 1
        trigma_tracking.track_dropdown(); // 2
        trigma_tracking.track_static_feature_button(); // 3
        trigma_tracking.track_feature_buttons(); // 4
        trigma_tracking.track_product_list(); // 5
        trigma_tracking.track_footer(); // 6 
        trigma_tracking.track_feature_panels(); //7
    }
}



$(document).ready(function() {
	trigma_header.init();
	trigma_forms.init();
	trigma_global.init();
	trigma_tracking.init();
});


