$(document).ready(function (e) {
	$('.preloading').hide();
	
	setInterval(function(){
		var active_id = $('.autoloop_active_speaker').attr("id"); 
		var current_id = active_id.split("_");
		var id = parseInt(current_id[1]) + 1;
		if(id === parseInt($('#config_flag_last_speaker').val()))
			id = 1;
		$('#'+active_id).hide();
		$('#'+active_id).removeClass('autoloop_active_speaker');
		
		$('#speaker_'+id).show();
		$('#speaker_'+id).addClass('autoloop_active_speaker');
	}, $('#config_autoloop_loudspeaker_interval').val());

	$('.loudspeaker_prev_click').click(function(){
		var prev_id = $(this).attr("id");
		var prev = prev_id.split("_");
		var id = parseInt(prev[1]) - 1;
		if(id === 0)
			id = parseInt($('#config_flag_last_speaker').val()) - 1;
		$('#speaker_'+prev[1]).hide();
		$('#speaker_'+prev[1]).removeClass('autoloop_active_speaker');
		
		$('#speaker_'+id).show();
		$('#speaker_'+id).addClass('autoloop_active_speaker');
		
		return false;
	});

	$('.loudspeaker_next_click').click(function(){
		var next_id = $(this).attr("id");
		var next = next_id.split("_");
		var id = parseInt(next[1]) + 1;
		if(id === parseInt($('#config_flag_last_speaker').val()))
			id = 1;
		$('#speaker_'+next[1]).hide();
		$('#speaker_'+next[1]).removeClass('autoloop_active_speaker');
		
		$('#speaker_'+id).show();
		$('#speaker_'+id).addClass('autoloop_active_speaker');
		
		return false;
	});

	$("#loudspeaker_title_container").toggle(
		
		function() { //minimise loudspeaker
			//$.cookie("loudspeaker_cookie", "hide", { path: '/',expires: 10 });
			
			var base_url = $('base').attr("href");
			var form_data = {
				ajax:1
			}
			$.ajax({
				url: base_url+"index.php/site/ajax_set_hide_session",
				type: 'POST',
				data: form_data,
				//dataType: 'json',
				success: function(msg) {
					//alert(msg);
				}
			});
			
			//alert($('#loudspeaker_title_container .nav').attr("id"));
			$("#loudspeaker_container_wrapper").hide();
			$('#button_louspeaker_minimise').hide();
			$('#button_louspeaker_open').show(); $('#button_louspeaker_open').css('display', 'inline');
		},
		function() { //open loudspeaker
			//$.cookie("loudspeaker_cookie", null, { path: '/', expires: -20 });
			var base_url = $('base').attr("href");
			var form_data = {
				ajax:1
			}
			$.ajax({
				url: base_url+"index.php/site/ajax_unset_hide_session",
				type: 'POST',
				data: form_data,
				//dataType: 'json',
				success: function(msg) {
					//alert(msg);
				}
			});
			$("#loudspeaker_container_wrapper").show();
			$('#button_louspeaker_minimise').show(); $('#button_louspeaker_minimise').css('display', 'inline');
			$('#button_louspeaker_open').hide();
		}
		
	);

	setInterval(function(){
		$('#loudspeaker_refreshing').show();
		setTimeout("$('#loudspeaker_refreshing').hide()", 2000);
	}, 50000);
	
	$('#shortcut_button').show();
	$('#shortcut_button').click(function(){
		$('.shortcut_menu').animate({height: 'show'});
		$(this).hide();
		$('#shortcut_back').show();
		return false;
	});

	$('.shortcut_menu').mouseleave(function(){
		$('.shortcut_menu').animate({height: 'hide'});
		$('#shortcut_back').hide();
		$('#shortcut_button').show();
	});

	//$('body').click(function(){
	$('#shortcut_back').click(function(){
		$('.shortcut_menu').animate({height: 'hide'});
		//$(this).hide();
		$('#shortcut_back').hide();
		$('#shortcut_button').show();
		return false;
	});

	/* back to top */
	$('.backtotop').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
	});



	/* product gallery (will be move...)*/
	$('.option_click').change(function(){
		$('#paginate_form').submit();
	});

	/* end of product gallery */

});



