 //GA analytics
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-2555190-8']);
    _gaq.push(['_trackPageview']);

    (function () {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
    })();


$(document).ready(function () {

    //Common function
    onloadEvents();

	//Single functions
    if ($.isPage('azienda.html')) {

        bannerVideo();
		
		$('#slideGallery a').lightBox();
		$('#slideGallery').cycle({
            fx: 'fade'
        });
		

    } else if ($.isPage('produzione.html')) {

        bannerVideo();
		
		$('#slideGallery a').lightBox();
		$('#slideGallery').cycle({
            fx: 'fade'
        });

    } else if ($.isPage('organizzazione.html')) {

        bannerVideo();
		
		$('#slideGallery a').lightBox();
		$('#slideGallery').cycle({
            fx: 'fade'
        });

    } else if ($.isPage('dove_siamo.html')) {

        initialize();

    } else if ($.isPage('contatti.html')) {

        validateForm();

        $('#readConditions').click(function () {
            $('#conditions').toggle(200);
            return false;
        })
    }


});

/****************************************/
/************** FUNCTIONS ***************/
/****************************************/

//Startup function


function onloadEvents() {

    //Main image resizing
    $('#mainImage').supersized();

    /*$('#menu').animate({
        bottom: "25px"
    }, 800)*/;

}

// @info 	Check current pag
// @usage	if($.isPage('pageName'))
jQuery.isPage = function (checkFor) {

    var url = window.location.pathname;
    var page = url.split('/');
    page.reverse();

    if (checkFor == page[0]) {

        return true;
    } else {
        return false;
    }
}

//Manage video loading


/*function startVideo() {

    var swfplayer = "../swf/player.swf";
    var videoname = $('a#videoStart').attr('rel');
    var lang = $('a#videoStart').attr('class');
    var videopath = "../flv/" + lang + "/" + videoname + ".flv";
    var so = new SWFObject(swfplayer, '', '700', '394', '9');

    $('#videoWrp').fadeIn(500, function () {

        so.addParam('menu', 'false');
        so.addParam("wmode", "opaque");
        so.addParam('FlashVars', 'videodir=' + videopath);
        so.write('videoIn');

    })

    $('a#videoStop').click(function () {

        $('#videoWrp').fadeOut(500, function () {

            $('#videoIn').remove();
            $('#videoStage').html('<div id="videoIn"></div><div id="closeVideoBtn"><a id="videoStop" href="">Close video</a></div>');

        })

        return false;
    })
}*/

//Manage banner video
function bannerVideo() {

    var swfplayer = "../swf/player.swf";
    var videoname = $('a#videoStart').attr('rel');
    var videopath = "../flv/" + videoname + "_banner.flv";
    var so = new SWFObject(swfplayer, 'banner', '240', '160', '9');

    //Write swf object
    so.addParam('menu', 'false');
    so.addParam("wmode", "transparent");
    so.addParam('FlashVars', 'videodir=' + videopath);
    so.write('bannerVideo');

    /*$('a#videoStart').click(function () {

        startVideo();

        return false;

    })*/
}



//Stretch image background
(function ($) {

    //Resize image on ready or resize
    $.fn.supersized = function () {

        var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);

        $().ready(function () {
            $('#mainImage').resizenow();
        });
        $(window).bind("resize", function () {
            $('#mainImage').resizenow();
        });
    };

    //Adjust image size
    $.fn.resizenow = function () {

        var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);

        return this.each(function () {

            //Define image ratio & minimum dimensions
            var minwidth = options.minsize * (options.startwidth);
            var minheight = options.minsize * (options.startheight);
            var ratio = options.startheight / options.startwidth;

            //Gather browser and current image size
            var imagewidth = $(this).width();
            var imageheight = $(this).height();
            var browserwidth = $(window).width();
            var browserheight = $(window).height();

            //Check for minimum dimensions
            if ((browserheight < minheight) && (browserwidth < minwidth)) {
                $(this).height(minheight);
                $(this).width(minwidth);
            }
            else {
                //When browser is taller	
                if (browserheight > browserwidth) {
                    imageheight = browserheight;
                    $(this).height(browserheight);
                    imagewidth = browserheight / ratio;
                    $(this).width(imagewidth);

                    if (browserwidth > imagewidth) {
                        imagewidth = browserwidth;
                        $(this).width(browserwidth);
                        imageheight = browserwidth * ratio;
                        $(this).height(imageheight);
                    }

                }

                //When browser is wider
                if (browserwidth >= browserheight) {
                    imagewidth = browserwidth;
                    $(this).width(browserwidth);
                    imageheight = browserwidth * ratio;
                    $(this).height(imageheight);

                    if (browserheight > imageheight) {
                        imageheight = browserheight;
                        $(this).height(browserheight);
                        imagewidth = browserheight / ratio;
                        $(this).width(imagewidth);
                    }
                }
            }
            return false;
        });
    };

    $.fn.supersized.defaults = {
        startwidth: 1920,
        startheight: 1080,
        minsize: .50,
        slideshow: 1,
        slideinterval: 5000
    };

})(jQuery);


//Initialize map


function initialize() {

    var myLatlng = new google.maps.LatLng(45.589927, 9.790629);
    var myOptions = {
        zoom: 10,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map"), myOptions);


    var image = 'http://80.91.50.130/colpack.it/graphics/tipMap.png';
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map
        //sicon: image
    })
}


//Validate form
/*
function validateForm() {

    $("input[name=sendRequest]").click(function () {
        var name = $("input[name=name]").val();
        var surname = $("input[name=surname]").val();
        var company = $("input[name=company]").val();
        var email = $("input[name=email]").val();
        var telephone = $("input[name=telephone]").val();
        var msg = $("textarea[name=message]").val();

        var error = false;
        var at = email.indexOf("@");
        var dot = email.indexOf(".");

        if (name == "") {
            error = true;
            $("input[name=name]").val("Insert name");
        }

        if (surname == "") {
            error = true;
            $("input[name=surname]").val("Insert Surname");
        }

        if (name == "") {
            error = true;
            $("input[name=email]").val("Complete Email");
        }

        if ((email == "") || (at == -1) || (dot == -1)) {
            error = true;
            $("input[name=email]").val("Complete Email");
        }

        if (msg == "") {
            error = true;
            $("textarea[name=message]").val("Complete");
        }

        if (error) {
            $('input[name=sendRequest]').animate({
                marginLeft: "3px"
            }, 200).animate({
                marginLeft: "-3px"
            }, 200).animate({
                marginLeft: "3px"
            }, 200).animate({
                marginLeft: "0"
            }, 200);
        } else {
            $.post("/lib/mail/mail.php", {
                name: name,
                surname: surname,
                company: company,
                telephone: telephone,
                email: email,
                message: msg
            });
            $('.theForm').fadeOut(500);
            setTimeout("$('.thxForm').fadeIn('1000')", 1000);
        }

        return false;
    });
}
*/
