var marquee = function(){ 
	var leftPos = $(".textMarquee").parent().width() + 10 + "px";	
	$(".textMarquee").animate(
	    {left: ($(".textMarquee").width() - $(".textMarquee").parent().width() - $(".textMarquee").parent().width())},
	    40000, function(){$(".textMarquee").css("left", leftPos); marquee();}
	 );
}

var showSelectOptions = function(){
	$(".selectOptions").hide();
	$(".selectOptions").css("visibility", "visible");
	$(".selectContainer").mouseleave(function(){
		$(".selectOptions").slideUp()
		$(".selectOptions").removeClass("opened");
	});
	$(".showSelectOptions").click(function(){
		var optionsId = $(this).attr("rel");
		if($(optionsId).hasClass("opened")){
			$(optionsId).slideUp();
			$(optionsId).removeClass("opened");
		}
		else{			
			$(optionsId).slideDown();
			$(optionsId).addClass("opened");
		}
		return false;
	});
}

var initShowTab = function(){
	$(".sliderLayer").hide();
	$(".sliderLayer").css("visibility", "visible");
	$(".sliderLayer").eq(0).fadeIn();
	$(".tabNav a").eq(0).addClass("selectedTab");
	$(".tabNav a").click(function(){
		if(!$(this).hasClass("empty")){
			var layerId = $(this).attr("rel");
			$(".sliderLayer").hide();
			$(layerId).fadeIn();
			$(".selectedTab").removeClass("selectedTab");
			$(this).addClass("selectedTab");
		}
		return false;
	});
}

var emptyField = function(){
	$(".fieldToEmpty").focus(function() {
		if($(this).val() == $(this).attr("rel")){
			$(this).val("");
		}
	});
}

$(document).ready(function(){
	if($(".marquee").is("div")) {
		$(".textMarquee").css("left", $(".textMarquee").parent().width() + 10 + "px");
		marquee();
	}
	if($(".showSelectOptions").is("a")) showSelectOptions();
	//if($(".tabNav").is("ul")) initShowTab();
	if($(".fieldToEmpty").is("input")) emptyField();
});