var d=document;
var tmr_panel='';
var current_panel=0;
var timeout_panel=4000;
var tmr_calendar='';
var slide_show_trigger=true;
function ge(obj){
   if(document.getElementById(obj)) {
     obj = document.getElementById(obj);
     return obj;
   } else {
     return false;
   }

}

function HideBlock(id)
{
	ge(id).style.display='none';
}
function ShowBlock(id)
{
	ge(id).style.display='block';
}

function InvertBlock(id)
{
	if(ge(id))
	{
		if(ge(id).style.display=='block')
			HideBlock(id)
		else	
			ShowBlock(id)
	}
}

function doLoad(div,action,value) {

    var req = new JsHttpRequest();	
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            switch(action){
            case 'concert_skoro':
            	
            	ge(div).innerHTML = req.responseText;
            	
            	w=getBounds('img_skoro');
            	//ge('panel_play_pause').style.width=w.width+'px';
            	
            		$('#skoro_ul').cycle({ 
            			fx:     'fade',    					
            			speed:  1000,						
            			timeout: 3500,
            			height:300,
            			cleartype:  1,
            			pause:0,
            			random:0,
            			startingSlide: 0,
            			pager:      '#nav', 
            		    pagerEvent: 'click' 
            		
            		});	
            		
            	break;
              default:
                ge(div).innerHTML = req.responseText;
              break;
            }
            if(req.responseJS)
            	if(req.responseJS['src'])
            		eval(req.responseJS['src']);
        }
    }   
    req.open(null, '/ajax.php', true);  
    req.send( { q: value ,div: div, action:action} );    	
 }
 
var old_open_sub_menu_id=0;

function get_sub_menu_ajax(id){
	var el_top = getBounds('left_menu_'+id).top;
	var el_left = getBounds('left_menu_'+id).left + getBounds('left_menu_text_'+id).width + 18;
	var el = ge('left_submenu_'+id);
	var anchor = ge('menu_anchor');
	if(el){
		el.style.left = el_left+'px';
		el.style.top = el_top+'px';
		el.style.display='';
	}
	
	if((old_open_sub_menu_id)&&(ge('left_submenu_'+old_open_sub_menu_id))&&(old_open_sub_menu_id!=id)){
		ge('left_submenu_'+old_open_sub_menu_id).style.display='none';
		if(ge('menu_anchor')) ge('menu_anchor').style.display='none';
	}
	if(el){
		anchor.style.left = el_left-6+'px';
		anchor.style.top = el_top+10+'px';
		anchor.style.display='';
	}
	
	old_open_sub_menu_id=id;
}

function getBounds(element)
{

	
	element = document.getElementById(element);
	if(element)
	{
	var left = element.offsetLeft;
	var top = element.offsetTop;
	for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
	{
		left += parent.offsetLeft - parent.scrollLeft;
		top += parent.offsetTop - parent.scrollTop
	}
	
	return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
	}
}
 
function getWinBounds(){
	var width = document.innerWidth?document.innerWidth:document.body.clientWidth;
	var height = document.innerHeight?document.innerHeight:document.body.clientHeight;
	return {width: width, height: height};
}

 
 function check_str(){
  var str=d.findform.str.value;
  if(str.length>3)
    {
     ge('findform').submit();
     return false;
    } else {
     alert('Слишком короткий запрос');
     return false;
    }
}

 function my_mas(mas,count)
 { 

	 HideBlock('panel_'+mas[current_panel]); 
		if(current_panel==count-1)		 
			 current_panel=0;	  
	 	else
			 current_panel=current_panel+1;	 
	 	ShowBlock('panel_'+mas[current_panel]);
 }
 
    
function is_IE6()
{
	var browser = navigator.appName;
	
    if (browser == "Microsoft Internet Explorer")
    {
    	var b_version = navigator.appVersion;

       	var re = /\MSIE\s+(\d\.\d\b)/;

        var res = b_version.match(re);

        if (res[1] <= 6){
 
        	return true;

        }

    } 
	return false;
}



function day_list_concert_show(concerts, id,num_week,cur_week)
{	
 	var calendar_info=ge('calendar_info');
 	calendar_info.innerHTML='<div style="border: 1px solid rgb(204, 204, 204); background: rgb(255, 255, 255) none repeat scroll 0% 0%;"><ul id="mini_list_cal"></ul></div>';
 	var mini_list_cal=ge('mini_list_cal');
 	
 	for(var key in concerts)
 	{
 		if(concerts[key].time===undefined && concerts[key].title===undefined)
 			continue;
 		else
 			mini_list_cal.innerHTML=mini_list_cal.innerHTML+'<li><span class="date">'+concerts[key].time+'</span>&nbsp;'+'<a href="/repertoire/concert'+concerts[key].concert_id+'.html">'+concerts[key].title+"</a></li>";
 	}
 	
	if(is_IE6())
	{
		if(num_week==6)
			calendar_info.style.bottom=(1149-getBounds(id).top)+'px';
		else
		 	calendar_info.style.bottom=(1120-getBounds(id).top)+'px';
		
		ge('calendar_info_anchor').style.left=(getBounds(id).left+6)+'px';
		ge('calendar_info_anchor').style.top=(getBounds(id).top-12)+'px';
		ge('calendar_info_anchor').style.display='block';
	}
	else
	{	
		
		ge('calendar_info_anchor').style.left=(getBounds(id).left+6)+'px';
		ge('calendar_info_anchor').style.top=(getBounds(id).top-12)+'px';
		ge('calendar_info_anchor').style.display='block';
		if(num_week==6)
			calendar_info.style.bottom=(501-getBounds(id).top)+'px';
		else		
			calendar_info.style.bottom=(470-getBounds(id).top)+'px';
		var browser = navigator.appName;		
	    if (browser == "Microsoft Internet Explorer")
	    {
	    	calendar_info.style.bottom=parseInt(calendar_info.style.bottom)+7+'px';
	    }
	}
	calendar_info.style.display='block';
}

function toggle_visibility (e) {
  $ (e).parent ().children ('div').each
(function () {
  if ( $ (e).next () [0] != $ (this) [0]) {$ (this).slideUp (1)} ;})
  $ (e).next (). slideToggle ('slow');
}

// $(document).ready(function(){
//   $("a.thickbox").click(function(){
//     return hs.expand(this);
//   });
// });

