function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    alert(curleft + " " + curtop);return [curleft,curtop];
}

$(document).ready(function() {  
    var dragPosition = 0;
    $("div.scrollable").scrollable();
    $(".prevPage").click(function(){return false;});
    $(".nextPage").click(function(){return false;});
    $(".scrollable .items a").lightBox();
    $(".text").jScrollPane({
        showArrows: true,
        scrollbarWidth: 5,
        dragMaxHeight: 23,
        animateTo: true
    });
    var $text = $('#page-content .text');
    $('#nav a').click(function() {
            var name = $(this).attr("href").substr(1);
            var obj = $("a[name='"+name+"']");
            var pos = $(obj).position();
            var txtHeight = $("#page-content .text").height();
            var scrollHeight = $("#page-content .jScrollPaneTrack").height();
            dragPosition = scrollHeight/100*(100*pos.top/txtHeight);
            positionDrag = dragPosition;
    		$text[0].scrollTo(pos.top);
    		return false;
    	}
    );
    $(".thumbs a").click(function(){
        var oldImg = $(".full-img img");
        var src = $(this).find("img").attr("src");
        $(".thumbs li").each(function(){ $(this).removeClass("active"); });
        $(this).parent("li").addClass("active");
        $(oldImg).fadeOut(2000, function(){
            $(this).remove();
            $(".full-img").append('<img src="'+src+'" alt="" />').hide().fadeIn(2000);
        });
        return false;
    });
});


/**
*  12.04.2010 - illusive
*  web-blog.org.ua
*/

// our timer variable
var timer;

/**
* This funtion emulate click on the btn
*/
function showNextSlide() {
    var active = $('ul.thumbs > li.active > a'); // search for active btn
    if (active.length == 0) active = $('ul.thumbs > li > a:first'); // or take the first
    if (active.parent().next().length>0) active.parent().next().children('a').trigger('click'); // emulate click to next btn
    else $('ul.thumbs > li > a:first').trigger('click'); // or it was a last btn - click to first 
    timer = setTimeout(showNextSlide,8000);// +4s for waiting effects   
}

jQuery().ready(function() {
    // start rotation if doc is ready
    timer = setTimeout(showNextSlide,4000);// 4s        
});

function showOnlineForm() {
    var api = $('#overlay').overlay({oneInstance: false, api: true});
    api.load();    
}
