/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function getWindowHeight() {
	  var windowHeight=0;
	  if (typeof(window.innerHeight)=='number') {
	    windowHeight=window.innerHeight;
	  }
	  else {
	    if (document.documentElement&&document.documentElement.clientHeight) {
	      windowHeight=document.documentElement.clientHeight;
	    }
	    else {
	      if (document.body&&document.body.clientHeight) {
	        windowHeight=document.body.clientHeight;
	      }
	    }
	  }
	  return windowHeight;
}


function setMarginFrame(h)
{
//    h = 400;
    c_h = getWindowHeight();
    margin = (c_h - h)/2;
    document.getElementById("iframe_block").style.marginTop = margin+'px';
}




function adminForm( id, formName, param_1, action, param_2 )
{

    src = '/admin/frame_form.php?form='+formName+'&action='+action+'&id='+id+'&param_1='+param_1+'&param_2='+param_2;


    //alert(formName);

    switch(formName)
    {

        case 'language':
            h = 270;
            w = 800;
        break;
        case 'title':
            h = 270;
            w = 800;
        break;
        case 'home':
            h = 270;
            w = 800;
        break;
        case 'red_question':
            h = 300;
            w = 800;
        break;
        case 'album':
            h = 500;
            w = 800;
        break;
        default:
            h = 600;
            w = 900;
    }

    setMarginFrame(h); //установка отступа сверху

    document.getElementById("iframe_block").style.width = w+'px';
    document.getElementById("iframe_block").style.height = h+'px';
    document.getElementById("form_frame").style.width = w+'px';
    document.getElementById("form_frame").style.height = h+'px';
    document.getElementById("form_frame").src = src;

    $('.adm_form').css('display', 'block')
    .animate({opacity: 1}, 400);
}

$(document).ready(
  function()
  {
    $(".adm_form_bg").click(function(){
        $('.adm_form').css({display: "none", opacity: "0"});
        location.reload();
    });


    
    //==== slideshow ====
    if( window.location.href.indexOf('volonter') > 0 || window.location.href.indexOf('camp') > 0 )
    {
        $('#slideshow').cycle({
            fx:    'fade', 
            speed:  1000,
            pause:  2
        });
    }


    //===== Разворачивание ответа FAQ ========
    $('.faq_txt_title').click(function(){
        var div = $(this).parent();
        $('.faq_txt', div).slideToggle(100);
    });

    //===== Вызов формы отправки сообщения =====
    $('.faq_send').click(function(){
        html_faq_form = '<div id="faq_send_main_block"><div id="faq_send_main_block_bg" onclick="closeFAQform()"></div><center><div id="faq_send_form_block"><a href="javascript:void(0)" id="faq_send_close" onclick="closeFAQform()"></a><h2>Задать вопрос</h2><form action="/admin/send_question.php" method="post" id="sendQustionForm"><input type="text" name="mail" value="Ваш E-mail" onclick="this.value=\'\'" /><textarea name="text" onclick="$(this).empty()" >Вопрос</textarea><a href="javascript:void(0)" id="faq_send_mail" onclick="sendQuestion()"></a><div id="qsendResult"></div></form></div></center></div>';
        $('body').prepend(html_faq_form);
        popupCenter();
    });
    

    
    //===== /Вызов формы отправки сообщения =====
    
    
  }
);


    //== выравнивание формы по центру
    function popupCenter()
    {
        bodyWidth = $('body').outerWidth();
        formWidth = $('#faq_send_form_block').outerWidth();
        formLeftMargin = Math.ceil( (bodyWidth - formWidth) / 2 );
        $('#faq_send_form_block').css({'left':formLeftMargin+'px'});
    }
    //== /выравнивание формы по центру



    //===== Закрытие формы отправки сообщения ======
    function closeFAQform()
    {
        function removeSendForm(){
            $('#faq_send_main_block').remove();
        }
        $('#faq_send_main_block').animate({opacity:0},300, removeSendForm );
    }


function del_confirm( msg )
{
        if( msg == false )
            msg = 'Вы уверены что хотите удалить запись ?';
	return confirm( msg );
}

//function showmap()
//{
//    block = '<div id="YMapsID" style="width:600px;height:400px"></div>';
//    setMarginFrame(400); //установка отступа сверху
//    document.getElementById("iframe_block").style.width = '600px';
//    document.getElementById("iframe_block").style.height = '400px';
////    document.getElementById("form_frame").style.display = 'none';
//
////     $('#iframe_block').prepend(block);
////    $('#iframe_block').load('/pages/map.html');#YMapsID
////    $('.adm_form').css('display', 'block')
////    .animate({opacity: 1}, 400);
//        $('#YMapsID').animate({width: "600px", height: "400px"}, 400);
//
//}


// === group list === 
$(document).ready(
  function()
  {
    $(".group_list li").mouseover(function(){
        $('a.group_list_name', this).css({color: "#fff"});
        $('.group_list_code', this).css({color: "#fff"});
        $('.group_list_code div', this).css({display: "block"});
    });

    $(".group_list li").mouseout(function(){
        $('a.group_list_name', this).css({color: "#008dee"});
        $('.group_list_code', this).css({color: "#008dee"});
        $('.group_list_code div', this).css({display: "none"});
    });


    //=========== window height =============//
    function win_height()
    {
//        if( window.location.href.indexOf('language') > 0 || window.location.href.indexOf('speaking-clubs') > 0 || window.location.href.indexOf('library') > 0 )
//            return false;

        $('.wrapper-content').css({paddingTop: 0}, 0);
        user_win_h =    $(window).height();
        page_h =        $('#wrapper').outerHeight(true);
        content_h =     $('#main').height();

        if( typeof(content_h) != 'number' )
            content_h = $('#lang_resize').height();

//        alert(user_win_h +' - '+ page_h);

        if( user_win_h > page_h ) //если размер экрана больше размера блока контента
        {
//            new_content_h = content_h+(user_win_h-page_h);
//
//            $('#main').height(new_content_h);
//            $('#lang_resize').height(new_content_h);
//            $('#threecolumn').height(new_content_h);

            new_paddTop = (user_win_h-page_h)/2;
            $('.wrapper-content').css({paddingTop: new_paddTop});
        }
    }

//    timer_id = setTimeout( 'win_height()',500 );
//    clearTimeout(timer_id);
    win_height();
    
//    $('.sb-tabset li').click(function(){
//        win_height()
//    });

//    $('.tabset li').click(function(){
//        win_height()
//    });

   //=========== /window height =============//


  }
);


//===== ONLINE TEST =======
var graf_open = 'close';
function grafOpen()
{
    if(graf_open == 'close')
    {
        $('#graf-block').animate({height: '150px'}, 200);
        $('a.graf-btn-open').css('backgroundImage', "url(/images/bg-btn-test-grafik-close.gif)" );
        graf_open = 'open';
    }
    else
    {
        $('#graf-block').animate({height: '0px'}, 200);
        $('a.graf-btn-open').css('backgroundImage', "url(/images/bg-btn-test-grafik.gif)" );
        graf_open = 'close';
    }
}



//========== SEND MAIL ===========
function sendMail()
{
	var formOption = {
		success: function getServerQuestion(txt)
				{
					$(function(){
						$('.result').html(txt);
//                                                $('body').append(txt);
						$('.result').css('backgroundImage','none');
					});
				}
	};

	$(function(){
//		$('#result_or_mail').attr('value', mail_result );
		$('.result').html('&nbsp;');
		$('.result').css('backgroundImage','url(/images/ajax-loader.gif)');
		$('#sendMailForm').ajaxSubmit(formOption);
	});
}

//========== SEND QUESTION ===========
function sendQuestion()
{
	var formOption = {
		success: function getServerQuestion(txt)
				{
					$(function(){
						$('#qsendResult').html(txt);
//                                                $('body').append(txt);
						$('#qsendResult').css('backgroundImage','none');
					});
				}
	};

	$(function(){
//		$('#result_or_mail').attr('value', mail_result );
		$('#qsendResult').html('&nbsp;');
		$('#qsendResult').css('backgroundImage','url(/images/ajax-loader.gif)');
		$('#sendQustionForm').ajaxSubmit(formOption);
	});
};

