// JavaScript Document	
$.noConflict();
  jQuery(document).ready(function($) {		
	
	//NAV	 
	$(function(){	
		
		if( !$(".big").length > 0) {
			   
			   var path = location.pathname.substring(1);			   
			   if ( path ) $('nav ul li a[href$="' + path + '"]').attr('class', 'selected');
			   
			
			   
			   var prevURLpath = document.referrer;
			   var URLpath = window.location.pathname
			   var pathname = window.location.pathname;
          	   var pathname = pathname.split('/');
          	   var tester = pathname[1];
         		
			   if (tester != undefined) {

                jQuery('nav ul li a').each(function(){

                    var test = jQuery(this).attr('href');

                   

                     if (test.match(tester, 'g')){

                       jQuery(this).addClass('selected');

                     }
                     
                     
                 	if (URLpath.match('_webapp', 'g') ) {
            			if (prevURLpath.match(test, 'g') ) {
                			jQuery(this).addClass('selected');
            			}  
            	     }
            	     
            	   if (jQuery('nav ul li.sub a').hasClass('selected')) {
            	   	  
            	   	  jQuery('nav ul li.web-app a').addClass('selected');
            	   }
				   
				   if (jQuery('nav ul li.shop a').hasClass('selected')) {
            	   	  
            	   	  jQuery('nav ul li.shop-online a').addClass('selected');
            	   }
            	     
                     
                     
                   });
                }
				
			}	
				
				$('nav ul li a:not(li.shop a)').prepend('<em>-&nbsp;</em>').append('<em>&nbsp;-</em>');
		
				$('em').hide();
				
				$(function(){
					$('nav ul li a:not(.selected)').hover(
						function(){
								$(this).find('em').fadeIn(300);
								
						},
						function(){
								$(this).find('em').fadeOut(300);
						}
						);
					});
				
				
				$('nav ul li a.selected:not(li.shop a.selected)').prepend('<em>-&nbsp;</em>').append('<em>&nbsp;-</em>');
				

     });
	
	//BUBBLE
		
    $(function () {
        $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 30,
                        right: 0,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });
	
	//BUBBLE SWATCH  WEB APP
		
    $(function () {
        $('.swatch-bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.swatch-trigger', this);
            var info = $('.swatch-popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 30,
                        right: 0,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });
	
	//BUBBLE SWATCH  SHOP
		
    $(function () {
        $('.shop-bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.shop-trigger', this);
            var info = $('.shop-popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 30,
                        right: 0,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });

     // SHOPPING CART EMPTY
	
		$('nav ul li.shop:contains("empty")').hide();
		$('nav ul li.shop:contains("view")').show();
	
	
	// IMAGE ENLARGE
	
	if ($('.small-images a').size() === 0){ $('#enlarge').hide(); return}
  	$('.small-images a').removeAttr('onclick');
    $('.small-images a').removeAttr('rel');
    $('.small-images a').click(function(e){
       e.preventDefault();
        });
    $('.small-images a').mouseover(function(e){
       $('.app-image-big img').attr("src",$(this).attr('href'));
        });
								  
 });
  
//END
