﻿/*

www.asapinformatica.com
A.S.A.P. Informatica di Stefano Porrino
Software and website development
Sviluppo Software e Soluzioni internet

*/


// Record browser tyle
var Browser = {
    find: function() {
        // Get the user agent to get the browser identifier
        var useragent = navigator.userAgent;
        // Match with the keyword to find out the browser type
        this.isKHTML = /Konqueror|Safari|KHTML/.test(useragent);
        this.isGecko = (/Gecko/.test(useragent) && !this.isKHTML);
        this.isOpera = /Opera/.test(useragent);
        this.isMSIE = (/MSIE/.test(useragent) && !this.isOpera);
        this.isMSIE7 = this.isMSIE && !(/MSIE 6\./.test(useragent) && !this.isOpera);
    }
}
// Bubble function
function bubble(id, left, top, delay, anispeed) {

    // exists id?
    if (document.getElementById(id) == undefined) return;

    // Cache the bubble object to speed up the process
    var obj = $("#" + id);

    // Get current width and height
    var width, height, w, h;
    width = obj.css("width");
    height = obj.css("height");
    // strip "px" to get the pixel value
    //alert(width);
    w = width.split("px")[0];
    h = height.split("px")[0];

    // shrink it to 0,0, and move it to target position
    obj.css({ opacity: 0, display: "block", width: "0px", height: "0px", left: left, top: top });
    // Hide the object
    obj.find("p").hide();
    // Set the timer to trigger the animation
    setTimeout(
	function() {
	    // To save new top and left
	    var left, top;
	    // Set all objects
	    obj.each(
		function() {
		    // Get current left and 
		    left = $(this).offset().left - (w / 2);
		    left = left + "px";
		    top = $(this).offset().top - (h / 2);
		    top = top + "px";
		    // Animate the object. Animate opacity and size, adjuct left and top also to keep object
		    // center. jQuery Effect.scale function is having bug that fails to keep the position
		    // after animation, so manually getting that effect
		    $(this).animate(
			{
			    width: width,
			    height: height,
			    opacity: 1,
			    left: left,
			    top: top
			},
			anispeed,
			function()	// This is callback function at the end of animation to make text visible
			{
			    $("p", this).slideDown(200);
			});
		});
	}, delay);
}

$(document).ready(function() {
    // Hack for IE6
    Browser.find();
    if (Browser.isMSIE && !Browser.isMSIE7) {
        $(".shot1").attr("src", "_autostima/movimento.png");
        $(".shot2").attr("src", "_autostima/mente.png");
        $(".shot3").attr("src", "_autostima/salute.png");
    }
    // Set bubble
    // ID, left, top, delay, animation delay
    bubble('asap1-bubble', 200, 400, 200, 1100);
    bubble('asap2-bubble', 400, 200, 400, 1100);
    bubble('asap3-bubble', 550, 400, 600, 1100);
    //bubble('downloads-bubble', 800, 300, 800, 1100);
});
