var switchScreenInterval = 5000;
var show_notify = 0;

function startAnimation() { 
        $("#phone-frame") 
        .animate({"opacity":1}, 500); 
        $("#coming-soon") 
        .animate({"opacity":1}, 500); 
        $("#socials").css({display:"block"}); 
}



$(document).ready(function() {
    $("#phone-frame").css({"opacity":0});
    $("#coming-soon").css({"opacity":0});
    
    startAnimation();

    
    $("a.screen-page").click(function() {
	if (! animating) {
	    $("a.screen-page").removeClass("active");
		var pageNum = this.href.substr(this.href.indexOf("#")+1);
		$(this).addClass("active");
		animating = true;
		var els = $("#screenshots li");
		var width = parseFloat(els.css("width"));
		$("#screenshots").animate({"left":"-"+(width*pageNum)+"px"}, 200, screenshotsAnimateFinish);
	}
	return false;
    });
    
    if (navigator.userAgent.indexOf("iPhone") == -1) {
	$('a[rel=screenshot_group]').fancybox({
	    'padding':		0,
	    'overlayColor':	'#fff',
	    'transitionIn':	'elastic',
	    'transitionOut':	'none',
	    'titlePosition':	'over',
	    'titleFormat':	function(title, currentArray, currentIndex, currentOpts) {
				    return '';
				}
	});
    }
	$(".text, textarea").each(function () {
		$(this)
		.focus(function() {
			if (this.value == this.getAttribute("default") || this.getAttribute("highlight")) {
				this.style.color = "#000";
				if (! this.getAttribute("highlight"))
					this.value = "";
			}
		})
		.blur(function() {
			if (this.value == "" || this.getAttribute("highlight")) {
				this.style.color = "#999";
				if (! this.getAttribute("highlight"))
					this.value = this.getAttribute("default");
			}
		})
	});
	$("#notify-form").bind("submit", function() {
	    if (! checkFields(this) )
			return false;
 
		$.fancybox.showActivity();
		$.ajax({
			type		: "POST",
			cache		: false,
			url			: "/notify.php",
			data		: $(this).serializeArray(),
			success		: function(data) {
				resetForms();
				$("div#notify-div").hide();
				$.fancybox(data);
			}
		});
 
		return false;
	});
    setTimeout(switchScreenshots, switchScreenInterval);
});
	
function switchScreenshots() {
    if (! animating) {
	animating = true;
	var els = $("#screenshots li");
	var width = parseFloat(els.css("width"));
	if (parseFloat($("#screenshots").css("left")) == ((els.length-1)*width)*-1) {
	$("#screenshots").animate({"left":"0px"}, 200, screenshotsAnimateFinish);
	} else {
	    $("#screenshots").animate({"left":"-="+width+"px"}, 200, screenshotsAnimateFinish);
	}
    }
    setTimeout(switchScreenshots, switchScreenInterval);
}

var animating = false;
function screenshotsAnimateFinish() {
    animating = false;
    var dots = $("a.screen-page");
    var els = $("#screenshots li");
    var width = parseFloat(els.css("width"));
    var activeDot = Math.round(parseFloat($("#screenshots").css("left"))*-1 / width);
    dots.removeClass("active");
    $(dots[activeDot]).addClass("active");
}

function _store()
{
    $("div#notify-div").show();
}
function resetForms () {
	$(".text, textarea").each(function () {
		$(this).val($(this).attr("default"));
		$(this).css({"color":"#999"});
	});
}
 
function checkFields (f) {
	var result = true;
	$(".text, textarea", f).each(function () {
		if (this.value == "" || this.value == this.getAttribute("default")) {
			$(this)
			.css({"backgroundColor":"#FCC"})
			.animate({"backgroundColor":"#FFF"}, 500);
			result = false;
		}
	});
	return result;
}

