﻿var tickerWidth;
var tickerContainerWidth;

$(document).ready(

	function () {
	    rotation();

	    $('#signup').click(function (e) {
	        $('#sign_up').lightbox_me({
	            centered: true
	        });
	        e.preventDefault();
	    });

	    $("select").change(function () {
	        if ($(this).val() == "IE") {
	            $("#AgeCheckLabel").html("I am over 18");
	        } else {
	            $("#AgeCheckLabel").html("I am over 16");
	        }
	    });

	    $('#slider1').anythingSlider({
	        width: 371,          // Override the default CSS width
	        easing: 'easeInOutExpo',
	        startText: "",   // Start button text
	        stopText: "",
	        autoPlay: true
	    });

	    $(".thumbNav").css({ "position": "relative" });
	    $(".thumbNav li").css({ "position": "absolute" });
	    $(".thumbNav li").eq(0).css({ "left": "0" });
	    $(".thumbNav li").eq(1).css({ "left": "30px" });
	    $(".thumbNav li").eq(2).css({ "left": "60px" });
	    $(".thumbNav li").eq(3).css({ "left": "90px" });
	    $(".thumbNav li").eq(4).css({ "left": "120px" });
	    $(".thumbNav li").eq(5).css({ "left": "150px" });


	    $(".video").click(function () {

	        if ($(".video").hasClass("mainVideo")) {
	            $(".video").removeClass("mainVideo");
	        }

	        var thisVideo = $(this);
	        var position = thisVideo.position();
	        var top = position.top;

	        $(this).addClass("mainVideo");

	        $('html, body').animate({ scrollTop: position.top }, 800);


	    });

	    $(".video").hover(function () {
	        if (!$(this).hasClass("mainVideo")) {
	            $(this).addClass("hover");
	        }
	    }, function () {
	        $(this).removeClass("hover");
	    });

	    $("#egg").everyTime(10, function () {
	        setTimeout('$("#egg").animate({ top: "156px" }, 300).animate({ top: "166px" }, 300)', 1000);
	        setTimeout('$("#tache").animate({ top: "154px" }, 100).animate({ top: "157px" }, 100)', 1000);
	    });

	    setTimeout('$("#updates").animate({ left: "0" }, 250)', 250);
	    setTimeout('$("#with").animate({ left: "117px" }, 300)', 400);

	    tickerWidth = $("#tickerText li").width();
	    tickerContainerWidth = $("#ticker").width();

	    $("#tickerText li").css("position", "relative");
	    $("#tickerText li").css("top", "0px");
	    $("#tickerText li").css("left", $("#ticker").css("width"));

	    doAnimation();

	}
);

$(function () {

	var $glasses = $("#glasses");
	var goClockwise = true;
	rotate(0);
	function rotate(degree) {
	    $glasses.css({ WebkitTransform: 'rotate(' + degree + 'deg)' });
	    $glasses.css({ '-moz-transform': 'rotate(' + degree + 'deg)' });
	    timer = setTimeout(function () {
	        if (goClockwise) {
	            if (degree == 5) {
	                goClockwise = false;
	                rotate(--degree);
	            }
	            else rotate(++degree);
	        }
	        else if (!goClockwise) {
	            if (degree == -5) {
	                goClockwise = true;
	                rotate(++degree);
	            }
	            else rotate(--degree);
	        }

	    }, 15);
	}
}); 


function loopAnimation() {
    $("#tickerText li").css("left", $("#ticker").css("width"));
    doAnimation();
}

function doAnimation() {
    var duration = ((tickerWidth + tickerContainerWidth) * 17);
    $("#tickerText li").animate(
		{ "left": "-" + tickerWidth + "px" },
		duration,
		"linear",
		loopAnimation);
}

var rotation = function () {
    $("#wheel").rotate({
        angle: 0,
        animateTo: 360,
        callback: rotation,
        easing: function (x, t, b, c, d) {        // t: current time, b: begInnIng value, c: change In value, d: duration
            return c * (t / d) + b;
        },duration: 30000
    });
}
