function hideLoader(){
	$("div.ajax-loader").remove();
}
function showLoader(under_id){	
	if(document.location.pathname.indexOf("admin") != -1) limg = "3"; else limg = "3";
	var loader = $("<div class='ajax-loader'><img src='source/images/ajax-loader"+ limg+".gif'></div>");	
	loader.appendTo(document.body);						
	
	var p_object = (under_id == document.body?$(under_id):$("#"+under_id));	
	loader.css({
		'top':p_object.offset().top,
		'left':p_object.offset().left,
		'width':p_object.width(),
		'height':p_object.height()});
}
function MessageBox(text){			
			var box = $("<div class='messageBox'></div>");
			box.html("<br/>"+text+"<br/><br/><input type='button' class='button' value='Ok' onclick=\"$(this).parent().remove();\">");
			box.hide();
			box.appendTo(document.body);						
			box.css({
				'top':window.pageYOffset + screen.availHeight/3,
				'left':window.pageXOffset + screen.availWidth/3
			});
			box.show();			
		}
function loadContentTo(params, place, src_url){
	if(place == null) place = document.body;
	showLoader(place);
	$.post(src_url,params, function(content)
		{	
			hideLoader();								
			if(place != document.body){
				$("#"+place).hide();
				$("#"+place).html(content);				
			}else $(content).appendTo(place);						
			if(place != document.body)
				$("#"+place).animate({opacity: "show"}, 500);						
				
		}		
	);
	//print url to DIV  id=page_url
	if(document.getElementById("page_url") != null) $("#page_url").text(document.location.protocol+
		"//"+document.location.host+document.location.pathname+"?"+
		$.param(params));
	return false;
}
function _getElement(id){
	return document.getElementById(id);
}
function m_score(elem){
    link = $(elem).parent().attr("rel")+"&score="+elem.innerHTML;
    place = $(elem).parent().parent();    
    loader = $("<div class='ajax-loader'><img src='source/images/ajax-loader3.gif'></div>");	
    loader.appendTo(document.body);	
    loader.css({
            'top':place.offset().top,
            'left':place.offset().left,
            'width':place.width(),
            'height':place.height()});
    $.post(link,{}, function(content)
        {
            hideLoader();
            place.hide();
            place.html(content);
            place.animate({opacity: "show"}, 500,"linear",function(){
                $(".r_status").fadeOut(3000,function(){
                        $(".r_status").remove();
                    });
            });
        });
    return false;
}
function runMedia(link){
    ext = link.href.substr(link.href.lastIndexOf(".")+1).toLowerCase();
    url = link.href;
    switch(ext){
        case "jpg":
        case "png":
        case "gif":
            $(link).colorbox({title:$(link).attr("title"),open:true, maxWidth:"600px", maxHeight:"600px"});
            return true;
        case "flv":
            if(link.href.indexOf("http://") == -1)  url = "../"+url;
            $.colorbox({title:$(link).attr("title"),html:"<div style='width:400px;height:300px'><object style='width: 400px; height: 300px;' data='source/flv_player.swf?file="+url+"&amp;autoStart=false&amp;allowfullscreen=false' type='application/x-shockwave-flash'></object></div>"});
            return true;
        case "mp3":
            $.colorbox({title:$(link).attr("title"),html:"<div style='width:300px;height:20px'><object type='application/x-shockwave-flash' data='source/mp3_player.swf'  width='300' height='20'><param name='movie' value='source/mp3_player.swf' /><param name='FlashVars' value='showvolume=1&width=300px&mp3="+url+"' /></object></div>"});
            return true;
    }
    return false;
}
function redirectLinks(container){
    if(container == '#page_main')
        $('.jcarousel-skin-m_tool a').colorbox({maxWidth:"600px", maxHeight:"600px",current: "изображение {current} из {total}"});
    $(container+ ' a:not(.jcarousel-skin-m_tool a)').click(function(){
            if(runMedia(this)) return false;
            return true;
            //remove comment to ajax site
            /*url = $(this).attr("href").replace("index.php", "page_main.php");
            if(url.indexOf("http:") != -1) return true;
		
            if( run_redirect == 1 ){
            	run_redirect++;
            	$("#afisha").remove();//slideUp('slow', function(){$(this).remove();});
                loadContentTo({},'page_right',$(this).attr("href").replace("index.php", "page_right.php"));
            }
            loadContentTo({},'page_main',url);	
            return false;*/
	});
}
/*run when site is first time loaded*/
function onInitSite(){
	initMenu("#m_catalog");
        //remove comment to ajax site//redirectLinks("#scene a, #page_footer a, #m_catalog");	
}
/*
function _getElementAttr(id,attr){
	var elem = document.getElementById(id);
	if(elem != null) 
	elemen
}*/
