var c = 2;
var to = 4000;
var speed = 500;
var minus = 325;
var timer = null;
var bwidth = 60; // width of .b
var bmarg  = 5; // margin of .b
var blocks = 5; // sum of .b

jQuery(function(){
//    $('.search-results').html('hello' + $('.m').width() + '===' + $('#hslider').width()); // !!!debug
    $('#content a:has(img), .contentpaneopen a:has(img)').lightBox();
    $(".m").css({ width: (mwidth())+"px", 'margin':'0'});
});

//$(window).resize(function(){ $(".m").css({ width:mwidth()+"px" }); });

function mwidth(){ // getting width of .m
    var slider = $('#hslider');
    w = (slider.width() - (bwidth + bmarg) * blocks);
    return w;
}

function header_slide(){
    $(".b").css({'margin-left':bmarg+'px', 'width':bwidth+'px'});
    $(".m").css({ width: (mwidth())+"px", 'margin':'0'});
    
    timer = setTimeout("autoslide()", to);

 ////### binding click
    $(".b").click(function(){
        var id = "#"+$(this).attr("id");
//        $('.search-results').html('zello' + $('.m').width() + ' -- ' + id + '===' + $('#hslider').width()); // !!!debug
        if (typeof timer == 'number') clearTimeout(timer);
        if ($(this).hasClass('m')) {
            url = $(this).find('span.url').attr('title');
            if (url) window.location = url;
        }
        else {
            slide(id);
            c = parseInt(id.slice(7))+1;
            timer = setTimeout("autoslide()", to);
            $(".slplay").css({display:"none"});
            $(".slpause").css({display:"block"});
        }
    });
}

function slide(id) {
	$(".m").animate({width: "60px"}, speed, function(){ $(this).removeClass("m"); $(this).addClass("b"); });
	$(id).animate({width: mwidth()+"px"}, speed, function(){ $(this).addClass("m"); });
}

function autoslide(){
	if (typeof timer == 'number') clearTimeout(timer);
	if (c>6) c=1;
	var id = "#banner"+c;
	slide(id);
	c+=1;
	timer = setTimeout("autoslide()", to);  
}

function getWindowSizes() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function slideMenu() {
    $(".slide > a").click(function(){
        var $kids = $(this).next();
        $kids.slideToggle(200);
        return false;
    });

    var path = document.location.pathname;
    $(".slide + ul").each(function() {
        var e = $(this);
        var name = e.attr('class');
        //if ($.cookie('show_' + name) == '0') e.hide();
        if (name == 'slide1') {
            e.show();
        } else if (name == 'slide2') {
            if (path.indexOf('/guided/') != -1) e.show(); else e.hide();
        } else if (name == 'slide3') {
            if (path.indexOf('/lazy/') != -1) e.show(); else e.hide();
        }
    });

    $(".slide").click(function() {
        var e = $(this).next();
        var name = e.attr('class');
        if (e.is(":hidden")) {
            e.slideDown("slow");
            $.cookie('show_' + name, '1');
        } else {
            e.slideUp("slow");
            $.cookie('show_' + name, '0');
        }
    });
}
