var x4Loads = 0;

function x4promo(id) {
	$(function(){
		var animationDuration = '5000';
		
		var front = $('#pss_front');
		var slide = $('#pss_'+id);
		var container = $('.x4Promo .wrapper');
		var height = container.height();
		var width = container.width();
		
		switch(id){
			case 'phone':
				x4resetSlide(slide, height, width, height, width);
				x4aniFront(front, -height, -width);
				x4aniSlide(slide, id);
				break;
			case 'music':
				x4resetSlide(slide, height, -width, height, width);
				x4aniFront(front, -height, width);
				x4aniSlide(slide, id);
				break;
			case 'video':
				x4resetSlide(slide, -height, width, height, width);
				x4aniFront(front, height, -width);
				x4aniSlide(slide, id);
				break;
			default:
				x4resetSlide(slide, -height, -width, height, width);
				x4aniFront(front, height, width);		
				x4aniSlide(slide, id);
				break;
		}

		return false;

		

		function x4resetSlide(slide, top, left, height, width){
			slide.css({
				"top": top,
				"left": left,
				"height": height,
				"width": width
			});
			return false;
		}
	
		function x4aniFront(front, top, left){
			front.animate({
				top: top,
				left: left
			}, animationDuration, function(){
				front.hide();	
			});
			return false;
		}

		function x4aniSlide(slide, id){
			slide.animate({
				top: 0,
				left: 0
			}, animationDuration, function(){
				x4addResetButton(slide, id);
			});
			return false;
		}

		function x4addResetButton(slide, id){
			slide.append('<a href="#" onclick="x4resetAll(\''+id+'\');return false;" id="x4Reset"></a>');
		}
	});
}

function x4resetAll(id)
{
	var animationDuration = '5000';

	var front = $('#pss_front');
	var slide = $('#pss_'+id);
	var container = $('.x4Promo .wrapper');
	var height = container.height();
	var width = container.width();

	$('#x4Reset').remove();
	
	front.css({
		"top": -height,
		"left": 0
	}).show();

	slide.animate({
		top: height
	}, animationDuration);

	front.animate({
		top: 0
	}, animationDuration);

	return false;
}

function x4loadCallback()
{	
	x4Loads = x4Loads + 1;

	if (x4Loads == 4) {
		setTimeout('x4loadSlider()', 2500);
	}
}

function x4loadSlider()
{
	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",
		autoPlay: false,
		startStopped: false,
		delay: 3000,
		animationTime: 600,
		hashTags: false,
		buildNavigation: false,
		pauseOnHover: true
        });
}
