$(document).ready(function(){ 
    // Drop down menus
    $("ul.sf-menu").supersubs({ minWidth: 12, maxWidth: 27, extraWidth: 1 }).superfish({speed: 'fast', autoArrows: false, animation: {height:'show'} }).find('ul').bgIframe({opacity:false}); 
    // Text over text boxes
    $('label').labelOver('over-apply');

    //default button setting
    // do we need to increment .length manually?
    $btn = $('.gelbtn34d'); $btn.add($('.gelbtn150d'));
    var $form = $btn.parents('.form'); 
    $form.keypress(function(e){ 
        if (e.which == 13 && e.target.type != 'textarea') { 
            if ($btn[0].type == 'submit') 
                $btn[0].click(); 
            else
                eval($btn[0].href); 
            return false; 
        } 
    }); 

    if ($('#jcarousel01').length > 0){
        $('#jcarousel01').html('');
        $('#jcarousel01').jcarousel({ size: jcarousel01_itemList.length, itemLoadCallback: {onBeforeAnimation: jcarousel01_itemLoadCallback} });
    }

    $('#sc0105').localScroll({ target:'#sc0105', axis:'xy', queue:true, hash:false, duration:1000 });
    $('#sc0104').localScroll({ target:'#sc0104', axis:'xy', queue:true, hash:false, duration:1000 });

    $(".expandable ul").toggle();
    $(".expandable").click(function(e) { if ($(e.target).children('ul').length > 0) { $(e.target).children('ul').toggle('fast'); } else { $(e.target).parent().children('ul').toggle('fast'); } });
   
});

function jcarousel01_itemVisibleInCallback(carousel, item, i, state, evt) {
    var idx = carousel.index(i, jcarousel01_itemList.length);
    carousel.add(i, jcarousel01_getItemHTML(jcarousel01_itemList[idx - 1])); 
};

function jcarousel01_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i); 
};

function jcarousel01_itemLoadCallback(carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) { continue; }
        if (i > jcarousel01_itemList.length) { break; }
        var item = jQuery(jcarousel01_getItemHTML(jcarousel01_itemList[i-1])).get(0);
        tb_init(item);
        carousel.add(i, item);
     }; 
     $('a.toolTip').cluetip({splitTitle: '|', positionBy: 'fixed', leftOffset: -180, width: 255, showTitle: false, dropShadow: false, height:38 });
};

function jcarousel01_getItemHTML(item) {
    var url_m = item.url.replace(/___Thumbnail./g, '___Selected.');
    return '<a class="toolTip" href="' + url_m + '" title="|' + item.title + '"><img src="' + item.url + '" width="98" height="98" border="0" alt="' + item.title + '" /></a>'; 
};

