document.getElementsByTagName('html')[0].className += ' js';

//IE png fix with background-repeat and background-position
document.write('<!--[if IE 6]><script type="text/javascript">DD_belatedPNG.fix(\'div, span, a\');</script><![endif]-->');
function animateSub(){
    //bgSound('subway_enter.mp3');
    jQuery('.footerAnimated').css('left', -2 * jQuery(this).width()).animate({
        'left': '-18%'
    }, 18000, function(){
        //bgSound('subway_leave.mp3');
    }).animate({
        'opacity': 1
    }, 5000).animate({
        'left': '100%'
    }, 16000)
};

function bgSound(src){
    var embed = document.createElement('embed');
		embed.setAttribute('id', 'player');
    embed.setAttribute('width', 0);
    embed.setAttribute('height', 0);
    embed.setAttribute('border', 0);
    embed.setAttribute('menu', false);
    embed.setAttribute('autostart', true);
    embed.src = 'http://www.vitaminbomb.com/wp-content/themes/vitaminbomb/mp3/' + src;
    embed.volume = 50;
    document.getElementsByTagName('body')[0].appendChild(embed);
};

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setTime(exdate.getTime()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function mycarousel_initCallback(carousel){
    //	Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function(){
        carousel.startAuto(0);
    });
    
    carousel.buttonPrev.bind('click', function(){
        carousel.startAuto(0);
    });
    
    //	Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function(){
        carousel.stopAuto();
    }, function(){
        carousel.startAuto();
    });
}

window.onload = function(){
	var sesionTrain = getCookie('train_sound');
	if(sesionTrain != 'off' || sesionTrain == null){
		animateSub();
		setInterval(animateSub, 60000);
		document.cookie = "train_sound=off";
	}
};

jQuery(document).ready(function(){
    //services slider
    jQuery('.services a').append('<span id="slider"></span>');
    jQuery('.services a').hover(function(){
        jQuery('#slider').slideToggle(1000);
    }, function(){
        jQuery('#slider').slideToggle(1000);
    })
    
    //crete tooltips
    jQuery('.mainNav a').each(function(){
        var $title = jQuery(this).attr('title');
        jQuery(this).hover(function(){
            this.title = '';
            jQuery('body').append('<div class="tooltip">' + $title + '</div>')
            
        }, function(){
            this.title = $title;
            jQuery('.tooltip').remove();
        })
    });
    
    jQuery('.mainNav a').mousemove(function(e){
        jQuery('.tooltip').css({
            'top': e.pageY + 10,
            'left': e.pageX + 20
        })
    });
    
    jQuery('#mycarousel').jcarousel({
        auto: 5,
        visible: 3,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
    
    //auto input read
//    jQuery('.product_quantity').each(function(){
//        jQuery(this).change(function(){
//            if (jQuery(this).val() > jQuery(this).prev('.max_quantity').val()) {
//                jQuery(this).val(jQuery(this).prev('.max_quantity').val());
//            }
//        });
//    });
    
    jQuery('#mycarousel a').click(function(){
        window.location.href = this.href;
    });
});
