$(function() {
    var pathname = window.document.location.pathname;
    var currentmenu = 0;
    GetProjectFace(0);
    GetProjectFace(1);
    GetProjectFace(2);
    GetProjectFace(3);
    $("#m_sites").click(function () {
      if ($("#type0").is(":hidden")) {
        $("#type"+currentmenu).css("display", "none");
        $("#type0").slideDown();
        currentmenu = 0;
      } else {
        $("#type0").slideUp();
      }
    });
    $("#m_logos").click(function () {
      if ($("#type1").is(":hidden")) {
        $("#type"+currentmenu).css("display", "none");
        $("#type1").slideDown();
        currentmenu = 1;
      } else {
        $("#type1").slideUp();
      }
    });
    $("#m_print").click(function () {
      if ($("#type2").is(":hidden")) {
        $("#type"+currentmenu).css("display", "none");
        $("#type2").slideDown();
        currentmenu = 2;
      } else {
        $("#type2").slideUp();
      }
    });
//    $("#m_virtu").click(function () {
//      if ($("#type3").is(":hidden")) {
//        $("#type"+currentmenu).css("display", "none");
//        $("#type3").slideDown();
//        currentmenu = 3;
//      } else {
//        $("#type3").slideUp();
//      }
//    });
    if (pathname == '/'){
        $(".сarousel").jCarouselLite({
        visible: 1,
        auto: 5000,
        speed: 800,
        btnNext: ".next",
        btnPrev: ".prev",
        btnGo:
        [".bc1", ".bc2",
        ".bc3", ".bc4",
        ".bc5", ".bc6",
        ".bc7", ".bc8",
        ".bc9", ".bc10"],
        afterEnd: function(a){
            }
        });
    }
    if (pathname == '/virtualtour/'){
        $("#strelka").click(function () {
            $("#strelkabuttom").css("display", "none");
            $("#strelkabuttom1").css("display", "block");
            $("#strelkabuttom2").css("display", "block");

            $("#virtualtour1").css("display", "none");
            $("#flashmovie").css("display", "none");
            $("#virtualtour").css("display", "block");
        });
        $("#strelka1").click(function () {
            $("#strelkabuttom1").css("display", "none");
            $("#strelkabuttom").css("display", "block");
            $("#strelkabuttom2").css("display", "block");

            $("#virtualtour").css("display", "none");
            $("#flashmovie").css("display", "none");
            $("#virtualtour1").css("display", "block");
        });
        $("#strelka2").click(function () {
            $("#strelkabuttom2").css("display", "none");
            $("#strelkabuttom1").css("display", "block");
            $("#strelkabuttom").css("display", "block");

            $("#virtualtour").css("display", "none");
            $("#virtualtour1").css("display", "none");
            $("#flashmovie").css("display", "block");
        });
        $('#strelkabuttom').tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: " - ",
				fade: 250
			});
        $('#strelkabuttom1').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            fade: 250
        });
        $('#strelkabuttom2').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            fade: 250
        });
        //setborders()
        AC_FL_RunContent(
                    'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                    'width', '680',
                    'height', '440',
                    'src', 'kochubey_big zal',
                    'quality', 'high',
                    'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                    'align', 'middle',
                    'play', 'true',
                    'loop', 'true',
                    'scale', 'showall',
                    'wmode', 'transparent',
                    'devicefont', 'false',
                    'id', 'kochubey_big zal',
                    'name', 'kochubey_big zal',
                    'menu', 'true',
                    'allowFullScreen', 'false',
                    'allowScriptAccess','sameDomain',
                    'movie', 'kochubey_big zal',
                    'salign', '');

    }
    if (pathname.substr(0,9) == '/project/') {
        //if (pathname = pathname.substr(9);)
        pathname = pathname.substr(9);
        pathname = pathname.substr(0,pathname.lastIndexOf("/"));
        if (pathname != ''){
            GetProjectContentFace(pathname);
        }
    }
    //setTimeout(GetProjectFaceFooter(),1000);
    setTimeout("GetProjectFaceFooter()",2000);
});
function bookmark(a){
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();
    if (b.type == 'IE') window.external.AddFavorite(url,title);
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
}
function getBrowserInfo() {
    var t,v = undefined;
    if (window.opera) t = 'Opera';
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (window.sidebar) t = 'Netscape';
    return {type:t,version:v};
}
function GetProjectFace(type){
    $.post("/admin/MyAjax.php", {func: "GetProjectFace", type: type},
      function(data){
        var outstr = '<ul class="uproject">';
        $('#type'+type).html('');
        for(var i=0; data.projects.project[i]!= null; i++) {
            outstr += '<li class="lproject">';
            outstr += '<a class="aproject" href="/project/'+data.projects.project[i].id+'/">'+data.projects.project[i].head_text+'</a>';
            outstr += '</li>';
        }
        outstr+='</ul>';
        $('#type'+type+'').html(outstr);
  },"json");
}
function GetProjectContentFace(id_project){
    $.post("/admin/MyAjax.php", {func: "GetProjectContent", ip: id_project},
      function(data){
          var out = '';
          $('#projectcontent').html('');
          for(var i=0; data.projectcontent.content[i]!= null; i++) {
            var idContent = data.projectcontent.content[i].id;
            var text = data.projectcontent.content[i].text;
            var image = data.projectcontent.content[i].image;
            var type = data.projectcontent.content[i].type;
            if (type == 0){
                out += '<div id=img'+idContent+'>' +
                       '<div><img style="margin-left: 5px;margin-right: 5px;margin-top: 10px;margin-bottom: 10px; opacity: 1;" src='+image+' /></div>' +
                       '</div>';
            }
            if (type == 1){
                out +=  '<span style="width: 545px; padding-left: 80px;" class="t12838383">'+text+'</span>';
            }
          }
          $('#projectcontent').html(out);
  },"json");
}
function showtt(div){
    if (div == 'left'){
        $("#ttempty").css("display", "none");
        $("#ttleft").css("display", "block");
    }
    if (div == 'right'){
        $("#ttempty").css("display", "none");
        $("#ttright").css("display", "block");
    }
}
function hidett(div){
    if (div == 'left'){
        $("#ttempty").css("display", "block");
        $("#ttleft").css("display", "none");
    }
    if (div == 'right'){
        $("#ttempty").css("display", "block");
        $("#ttright").css("display", "none");
    }
}
function mouseOver(img){
    img.src = "/images/bgb2.jpg";
}
function mouseOut(img){
    img.src = "/images/bgb.jpg";
}
function ShowTour(id)
{
	if(document.getElementById('tour'+id).className!="play")
	{
	var file=document.getElementById('nametour'+id).value;
	AC_FL_RunContent(
	'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '680',
			'height', '440',
			'src', file,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', file,
			'bgcolor', '#faf8e0',
			'name', file,
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', file,
			'salign', '');
	for(i=1;i<=13;i++)
	{
		if(document.getElementById('tour'+i)!=null)
		document.getElementById('tour'+i).className="";
		if(document.getElementById('btn'+i)!=null)
		document.getElementById('btn'+i).style.visibility="hidden";
	}
	document.getElementById('tour'+id).className="play";
	document.getElementById('btn'+id).style.visibility="visible";
	}
}
function ActivTour(id)
{
    if(document.getElementById('tour'+id).className!="play")
    document.getElementById('tour'+id).className="activtour";
}
function desActivTour(id)
{
    if(document.getElementById('tour'+id).className!="play")
    document.getElementById('tour'+id).className="";
    //alert(document.getElementById('tour'+id).className)
}
function GetProjectFaceFooter(){
    var outstr = '<div id="footer">'+
            '<div style="margin-left:0; float:left; width: 140px;">'+
                '<p style="margin-top: 31px;"><a class="footer_logo" href="http://intrino.ru"></a></p>'+
            '</div>'+
            '<div style="margin-left:0; float:left; width:230px;">'+
                '<p style="font-size: 11px; display: block; color: rgb(149, 149, 149); font-family: Arial; margin-top: 35px;">2009 © Креативное агентство Intrino</p>'+
            '</div>'+
            '<div style="margin-left:0; float:left; width:240px;">'+
                '<p style="margin-top: 20px;"><a class="footer_phone" style="margin-bottom: 10px;"></a></p>'+
            '</div>'+
            '<div style="margin-left:0; float:left; width:150px;">'+
                '<span id="icon1" style="text-align: left; display: block;font-size: 11px;text-decoration: underline;  margin-left: 20px; padding-left: 20px; margin-top: 36px;"><a class="mail" href="mailto:mail@intrino.ru">mail@intrino.ru</a></span>'+
            '</div>'+
            '<div style="margin-left:0; float:left;">'+
                '<p style="margin-top: 36px;"><a onclick="return bookmark(this);" href="javascript:void(0);"><img style="border:0px;" alt="" src="/images/icon1.jpg"/></a></p>'+
            '</div>'+
		'</div>';
    $('#footercontainer').html(outstr);
}
//function setborders(){
//    var height=document.body.scrollHeight-194;
//    var width=document.body.scrollWidth;
//    if(width>1360)  {document.getElementById('allbody').width=1360;width=1360;}
//    document.getElementById("left").style.height=height+"px";
//    document.getElementById("right").style.height=height+"px";
//    document.getElementById("top").style.width=width-38+"px";
//    document.getElementById("bottom").style.width=width-38+"px";
//}