var defaultPostion = 20;
var target = 20;
var loginInProcess = false;
var loginOpen = false;
var lastOffset = 0;

$(document).ready(
	function(){
		$(".fady").fadeTo("fast",0.5);
		$(".fady").mouseover(
			function(){
				$(this)
					.clearQueue()
					.fadeTo("slow", 1);
				}
			);
		$(".fady").mouseout(
			function(){
				$(this)
					.clearQueue()
					.fadeTo("slow", 0.5);
				}
			);
		$("#menu ul li").mouseout(
			function(){
				slideMenuBG(defaultPostion);
			}
		);
		$("#menu ul li").click(
			function(){
				defaultPostion = target;
			}
		);
		
        $("#screen a img").css("visibility", "visible");
		$("#screen").coinslider({ width: 812, height: 305, navigation: true, delay: 5000, sDelay: 25, links: true, spw: 1, sph: 1});
		$("#loginBox").css(
			{
				"left": ($(window).width())+"px"
			}
		);
        
        $(".marquee")
            .marquee("marquee")
            .mouseover(
                function () {
                    $(this).trigger('stop');
                }
            )
            .mouseout(
                function () {
                    $(this).trigger('start');
                }
            )
            .mousemove(
                function (event) {
                    if ($(this).data('drag') == true)
                        this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
                }
            )
            .mousedown(
                function (event) {
                    $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
                }
            )
            .mouseup(function () {
              $(this).data('drag', false);
            })
            .css("cursor","pointer");
            
	}
)

function slideMenuBG(to){
	target = to;
	$("#menu")
		.clearQueue()
		.animate(
			{backgroundPosition: to+"px 0px"}
		);
}

function toggleLogin(){
	if(loginInProcess == false){
		loginInPorcess = true;
		var offset = $("#loginButton").offset().left;
		if(loginOpen == false){
			lasrOffset = ($(window).width()-$("#loginButton").offset().left-$("#loginButton").width());
			$("#loginButton")
				.animate(
					{"left": ($(window).width()-$("#loginButton").offset().left-$("#loginButton").width())+"px"},
					"slow",
					"swing",
					function(){
						$("#loginButton")
							.animate(
								{"left": ($(window).width()-offset-$("#loginBox").outerWidth()-$("#loginButton").width())+"px"},
								"slow",
                                "swing"
							);
						$("#loginBox")
							.show()
							.animate(
								{
									"left": ($(window).width()-$("#loginBox").outerWidth())+"px"
								},
								"slow",
								"swing",
								function(){
									loginInProcess = false;
									loginOpen = true;
								}
							)
					}
				);
		}else{
			$("#loginButton")
				.animate(
					{"left": lasrOffset+"px"},
					"slow",
                    "swing"
				);
			$("#loginBox")
				.animate(
					{
						"left": ($(window).width())+"px"
					},
				"slow",
				"swing",
				function(){
					$("#loginBox").hide();
					$("#loginButton")
						.animate(
							{"left": "0px"},
							"slow",
                            "swing"
						);
					loginInProcess = false;
					loginOpen = false;
				}	
			)	
		}
	}
}
