function initDropdowns(){
	$("p.dropdown").each(function(i, item){
		$("p.dropdown:eq("+i+")").find("select").change(function(){
			//if ($(this).val()=='')
			$("p.dropdown:eq("+i+")").find("span.selectValue").html(this.options[this.selectedIndex].text);
			//else
				//$("p.dropdown:eq("+i+")").find("span.selectValue").html($(this).val());
		});
	});
}

function MagicSlider(sliderId, leftArrow, rightArrow){
		this.sliderId = sliderId;
		this.leftArrow = leftArrow;
		this.rightArrow = rightArrow;
		
		this.pageWidth = $(this.sliderId + " div.mask").width();
		$(this.sliderId + " ul").css('width', $(this.sliderId + " div.mask ul li").length * ($(this.sliderId + " div.mask ul li").width() + parseInt($(this.sliderId + " div.mask ul li").css('margin-right'))));
		this.pages = Math.round($(this.sliderId + " div.mask ul").width() / $(this.sliderId + " div.mask").width());
		this.page  = 1;
		
		if(this.pages == 1){
			$(this.leftArrow + ", " + this.rightArrow).hide();
		}

		if(this.page == 1){
			$(this.leftArrow).hide();
		}
		
		var x = this;
		
		$(x.leftArrow).click(function(e){
			e.preventDefault();
			if(x.page > 1){
				$(x.sliderId + " div.mask").stop(true, true).animate(
					{
						scrollLeft: '-=' + x.pageWidth
					},
					300,
					'swing',
					function(){
						if(x.page > 1)x.page--;
						if(x.page < x.pages){
							$(x.rightArrow).fadeIn('fast')
						}
						else{
							$(x.rightArrow).fadeOut('fast');
						}
						
						if(x.page == 1){
							$(x.leftArrow).fadeOut('fast');
						}
						else{
							$(x.leftArrow).fadeIn('fast');
						}
					}
				);
			}
			
			else{
				$(x.sliderId + " div.mask").stop(true, true).animate(
					{
						scrollLeft: 0
					},
					300,
					'swing',
					function(){
						x.page = 1;

					}
				);
			}
		});
		
		
		$(this.rightArrow).click(function(e){
			
			e.preventDefault();
			if(x.page < x.pages){
				$(x.sliderId + " div.mask").stop(true, true).animate(
					{
						scrollLeft: '+=' + x.pageWidth
					},
					300,
					'swing',
					function(){
						if(x.page < x.pages){x.page++;}
						if(x.page < x.pages){
							$(x.rightArrow).fadeIn('fast')
						}
						else{
							$(x.rightArrow).fadeOut('fast');
						}
						
						if(x.page == 1){
							$(x.leftArrow).fadeOut('fast');
						}
						else{
							$(x.leftArrow).fadeIn('fast');
						}
					}
				);
			}
			
			else{
				$(x.sliderId + " div.mask").stop(true, true).animate(
					{
						scrollLeft: 0
					},
					300,
					'swing',
					function(){
						x.page = 1;
						$(x.leftArrow).fadeOut('fast');
						$(x.rightArrow).fadeIn('fast');
					}
				);
			}
		});
}

var sounds="";
var instance = "audioplayer";

function soundDidFinishPlaying(){
	alert("soundDidFinishPlaying");
}

function start(url){
	document.getElementById(instance).start( url );
}
function stop(){
	window.document.getElementById( instance ).stop();
}
function getSounds(){
	return sounds;
}


$(document).ready(function(){
	var s1 = new MagicSlider("#appSlider", "#appSlider a.leftArrow", "#appSlider a.rightArrow");
	var s2 = new MagicSlider("#slider", "#slider a.leftArrow", "#slider a.rightArrow");
	var s3 = new MagicSlider("#catSlider", "#catSlider a.leftArrow", "#catSlider a.rightArrow");
	var s4 = new MagicSlider("#banner", "#banner a.prevArrow", "#banner a.nextArrow");

	initDropdowns();
	
	var mp3list=new Array()
	$(".category_link").each(function(){
		if ($(this).attr('rel')) {
			mp3list.push($(this).attr('rel'));
			$(this).mouseover(function(){
				start($(this).attr('rel'));
			});
		}
	});

	sounds=mp3list.join("*");

	var flashvars = {};
	var params = {allowNetworking : 'all', allowScriptAccess : 'always'};
	var attributes = { id : instance, name : instance };


	// SWFObject embed by Geoff Stearns geoff@deconcept.com http://blog.deconcept.com/
	swfobject.embedSWF ("/assets/swf/InvisiblePlayer.swf?" + Math.random()*1, instance,
		1, 1, "9", null, flashvars, params, attributes
	);
	
	$(".faded").hover(
		function(){
			$(this).stop(true, true).animate({opacity: .6}, 200, 'swing');
		},
		function(){
			$(this).stop(true, true).animate({opacity: 1}, 200, 'swing');
		}
	);

	$("#header_login_form a.toggle_link").toggle(
		function(e){
			e.preventDefault();
			$("#header_login_form").stop(true, true).animate(
				{
					top: 0
				},
				300,
				'swing'
			);
		},

		function(e){
			e.preventDefault();
			$("#header_login_form").stop(true, true).animate(
				{
					top: -69
				},
				300,
				'swing'
			);
		}
	);
});
