/** 
 *  Common scripts file
 *  @version: 1.0 
 *  @require: jquery
 */

var currentPosition = 0; 
var currentVolume = 80;  
var player = null;
var playerReady = false;


// console.log
if (!window.console) { 
    window.console = {
        log: function(obj){ }
    };
}


// top up
if(TopUp) {

    TopUp.host = baseUrl +'js/topup/';
    TopUp.images_path = "images/";
    TopUp.players_path = "players/";

    TopUp.addPresets({
        "div.multimediaBox li a.top_up": {
            title: "{alt}",
            type: 'flashvideo',
            readAltText: 1,
            width: 300, 
            height: 30,
            shaded: 1
            },
        "div.photogallery ul li a.top_up": {
            title: "{alt} ({current} di {total})",
            group: "mycarousel",
            readAltText: 1,
            shaded: 1
            },
        "div.videogallery ul li a.top_up": {
            readAltText: 1,
            width: 500, 
            height: 400,
            shaded: 1
            },
        "div.follow ul li.icoMail a.top_up": {
            title: 'Segnala la pagina',
            type: 'iframe',
            width: 400, 
            height: 550,
            layout: 'flatlook',
            resizable: 0
            }
    });
}

$(document).ready(function() {
    emailProtection('a.email'); 
    printButtons('li.icoPrint a');
    loadNavbar('#nav ul.main li'); 
    loadCarousel('div.photogallery ul', {'scroll': 3});
    loadCarousel('div.videogallery ul', {'scroll': 1});
    if ($('#keyword')) {
        $('#keyword').focus(function(){
            $(this).attr('value', '')
        });
    }
    /*
    if ($('div.back p.left-bullet a')) {
        $('div.back p.left-bullet a').click(function(){
            window.history.back();
        });
    }
	*/
});

function loadCarousel(el, options)
{
    if ($(el).length > 0) {
        $(el).jcarousel(((options != undefined) ? options : {}));
    }
}

function loadNavbar(els)
{
    $(els).each(function(){
        $(this)
        .mouseenter(function(e){
                e.preventDefault();
                $(this).addClass('hover')
            })
        .mouseleave(function(e){
                e.preventDefault();
                $(this).removeClass('hover');
            });
    });
}

function emailProtection(elClass)
{
    $(elClass).each(function(){
        var el = $(this);
        var mail = el.text().replace('[AT]','@');
        var text = el.attr('title') || mail;
        var a = $("<a>", {
            "class": elClass.substring(1),
            "href": 'mailto:' + mail,
            text: text                
        });
        el.replaceWith(a);
    });
}

function printButtons(elClass)
{
    $(elClass).click(function(e){
        e.preventDefault();
        window.print();
    });
}
