$(document).ready(function() {
	// Menu at top side
	// Drop down action script
	$("ul li.menu1").mouseout(function(){
		$(this).removeClass('active')
	}).mouseover(function(){
		$(this).addClass('active').css('cursor','hand');
	});	
	$(".tutorial_videos a").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});	
	
	// Fold and collapse
	// Hide and display content action script
	
	var imgContainers = $('div.fold > div');
	imgContainers.hide().filter(':first').hide();

	$('.fold a').click(function () {
		$('div.fold > div').attr("style","display:none");
		$('div.fold div#' + this.hash.slice(1) +'').attr("style","display:block;padding-left:20px");
		 return false;
	});
	
	$('.fold a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		  var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				
				return false;
			}
		}
	});
	// Smooth scroll action script
	// Apply to scrolling to top and Fold and collapse
	if(location.hash){
		  var $target = $(location.hash);
		  $target = $target.length && $target
		  || $('[name=' + this.hash.slice(1) +']');
		  if ($target.length) {
			var targetOffset = $target.offset().top + 300;
			$('html,body')
			.animate({scrollTop: targetOffset}, 1000);
		   return false;
		  }

	}
	
	$("#product-level").change(function(){ 
		var permalinkpath = $(this).val();
		
		if( permalinkpath ){
			window.location.replace(permalinkpath);
		}
		return false;
	});
	/* ACCORDION */
	$('.acc_container').hide(); //Hide/close all containers
	$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
		}
		return false; //Prevent the browser jump to the link anchor
	});
	
});
