$(document).ready(function(){
    url_xml_rpc = js_global_root_url+'rpc/call.php';
    struct_param['header'] = new Object();
    struct_param['header']['version'] = '1.0.0';
    struct_param['header']['product'] = 'homepage';
    struct_param['header']['sessid'] = sessid;
    struct_param['header']['dialect'] = 'json';
    iso_encoding = 'utf-8';
    
    $('#email_input').bind('focus',function() {$(this).select()});
    $('#username_input').bind('focus',function() {$(this).select()});
    
    //$('#webcam_popup').jqm();
    
    // slideshow
    setInterval( "slideSwitch()", 5000 );
});


var firstDay = 6;  //14
var lastDay = 16;  //24
var nextDay = firstDay + 1;
var prevDay = firstDay - 1;
var winWidth = 6;

function scrollToDay(num) {
    $('#calendar_days').scrollTo($('#day_'+num),800,{axis:'x'});
}

function scrollNextDay() {
    if(nextDay <= lastDay-winWidth+1) {
        scrollToDay(nextDay);
        
        nextDay++;
        prevDay++;
    }
}

function scrollPrevDay() {
    if(prevDay >= firstDay) {
        scrollToDay(prevDay);
        
        nextDay--;
        prevDay--;
    }
}

function slideSwitch() {
    var active = $('#slideshow img.active');

    if (active.length == 0) {
        active = $('#slideshow img:last');
    }

    // use this to pull the images in the order they appear in the markup
    var next = active.next().length ? active.next() : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    //var sibs  = active.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length);
    //var next  = $(sibs[rndNum]);

    active.addClass('last-active');

    next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
}
