var activeId="slide-1";
var curclass="";
var inactiveId="slide-2";
var navDirect;
var goLeft,goRight;
var it=0;
var yScroll = 0;
var damn_mac_ff = function () {
	if($('#right-cont').is(':empty')){$('#right-cont').html('&nbsp;')}
	if($.browser.msie) {
	$('.conts').hide();
	setTimeout ("$('#left-cont').html(goLeft)",310);
	setTimeout ("$('#right-cont').html(goRight)",320);
	setTimeout ("$('.conts').show()",1200);	
	if ($.browser.version == '6.0') {
		setTimeout("$('#left-cont .name').css('width',$('#left-cont .nums').width())", 1201);
		setTimeout("$('#right-cont .name').css('width',$('#right-cont .nums').width())", 1201);
	}
	} else {
	$('.conts').fadeOut(300);
	setTimeout ("$('#left-cont').html(goLeft)",310);
	setTimeout ("$('#right-cont').html(goRight)",320);
	setTimeout ("$('.conts').fadeIn(300)",1200);
	}
	setTimeout ("hovertext()",1200);
}

$(document).ready(function(){
	$('.almin-main #logo img,.ny09-main #logo img,.vetta_liflet #logo img,.almin-main-take7 #logo img,.rkg-fs-main #logo img, .invest-site-main #logo img, .sima-main #logo img, .technonikol-template-main #logo img').attr('src','/i/logow.png');
	if (!strstr(window.location.href, 'dubby')) {
		if (!$('body').hasClass('nopngFix')) {
			$(document).pngFix();
		}
		//$(document).pngFix();
	}			   
	$('#logo span').css('width','112px').css('height','40px');
	
	$('body').append('<div id="preloader"><img src="/i/black.png" alt=""/><img src="/i/gray-white.gif" alt=""/><img src="/i/search-top.png" alt="" /><img src="/i/search-content.png" alt="" /><img src="/i/search-bottom.png" alt="" /><img src="/i/search-top-full.png" alt="" /><img src="/i/search-content-full.png" alt="" /><img src="/i/search-bottom-full.png" alt="" /></div>')
	
	if ($.browser.version == '6.0') {
		$('#left-cont .name').css('width', $('#left-cont .nums').width());
		$('#right-cont .name').css('width', $('#right-cont .nums').width());
	}
	
	$('#text .block').hover(function(){
		if ($('.image',this).is(':animated')){return false}
		$('.image',this).slideDown('fast');
		$('.image').hover(function(){
			$(this).show();
		},function(){
	});
	},function () {
		$('.image',this).slideUp('fast');
	});
	
	
	
	$(window).scroll(function(){	
		getscroll();	
		if($.browser.msie && $.browser.version == 6) {
			$('#panel').css('position','absolute').css('top','182px')
		} else {
			if (yScroll > 182) 
			{$('#panel').css('position','fixed').css('top','0px')} else 
			{$('#panel').css('position','absolute').css('top','182px')}	
		}
	});
	
	
	$('.icons a').click(function(){
		num = $('.icons a').index(this);
		if ($(this).hasClass('active')) {
			$('.icons a').removeClass('active');
			$('.twice_block').slideUp(500);
			$('#sliders').animate({height:56});
			return false			
		} else {
			$('.icons a').removeClass('active');
			$(this).addClass('active');
			$('.twice_block').slideUp(500);
			thisheight = $('.twice_block:eq('+num+')').height();
			$('#sliders').animate({height:thisheight+58});
			setTimeout("$('.twice_block:eq('+num+')').slideDown(500)",520);
			$('#bottom').css('bottom','0px')
			return false
		}
	});			
	
	
	
	$('.slide_up a').click(function(){
		$(this).parent().parent().parent().slideUp(500);
		$('#sliders').animate({height:56});
		setTimeout ("$('.icons a').removeClass('active');",500)
		return false
	});	
	
	$('.calendar_tbl td div').hover(function(){
		$('a.popup',this).slideDown('fast');
		$('a.popup').hover(function(){
		$(this).show();
		},function(){
	});
	}, 
	function(){
		$('a.popup',this).slideUp('fast');
	});	
	
	
	hovertext = function() {	
	$('.slide img').hover(function(){
	if ($('.slide, .slide-text').is(":animated")) {}
	else {
			$('.index_folio .slide-text div').pngFix();
			$(this).parent().parent().children('.slide-text').show();
	     }		 
	$('.slide-text').hover(function(){
		$(this).show();
		},function(){
	});	
	}, 
	function () {
		$(this).parent().parent().children('.slide-text').hide();	
	});	
	}	
	hovertext();

	
	
	
	$('#search input').click(function(){$(this).attr('value','')})
	
	$('#search-input span, #search-bottom a').click(function(){
		$('#frm_search').submit();
		return false
	});
	
	$("a[rel='blank']").click(function(){
		window.open($(this).attr('href'));
		return false
	});
	
	
	try
    {
	$('.calendar-list li a').click(function(){
		qu = $(this).parent().prevAll(':not(.empty)').size();	
		qu = qu - 1
		if ($('.calendar-pic-all').is(':animated')) {} else {
		$('.calendar-pic-all').scrollTo( $('.calendar-pic:eq('+ qu +')'), {speed:1500} );
		}
		return false
	});
	
	$('.calendar-year-pic a').click(function(){
		if ($('.calendar-pic-all').is(':animated')) {} else {									 
		$('.calendar-pic-all').scrollTo( $('.calendar-pic:last-child'), {speed:1500} );
		}
		return false
	});
		
	$('.quick li a').click(function(){
		$.scrollTo( $('#top_layer'), {speed:500});
		return false								
	});
	
	if (window.location.hash) {
  		anchor = window.location.hash.substr(1);
		anchor = anchor - 1
		$('.calendar-pic-all').scrollTo( $('.calendar-pic:eq('+ anchor +')'), {speed:0} );
		setTimeout("$('.calendar-pic-all').css('visibility','visible')",50);
	} else {
		$('.calendar-pic-all').scrollTo( $('.calendar-pic.current'), {speed:0});
		setTimeout("$('.calendar-pic-all').css('visibility','visible')",50);
	}
    }
    catch(e){;}
				
	
	$('.area-right').hover(function(){
		windowwidth = $(window).width();
		$('.area-content').animate({left:-4491+windowwidth+'px', marginLeft:0},5000);	
		},function(){
		$('.area-content').stop();
	});
			
	$('.area-left').hover(function(){
		$('.area-content').animate({left:0, marginLeft:0},5000);	
		},function(){
		$('.area-content').stop();
	});	
	
	
	if($.browser.safari ) {
		windowwidth = $(window).width();
		$('.area-content').css('left',windowwidth/2);			
	}
	
	
	$('#top_menu .menu td div a').hover(function(){
		$(this).parent().parent().addClass('act');	
	},function(){
		$(this).parent().parent().removeClass('act');	
	});
	
	
	$('.form input.text')
		.blur(function() {if(this.value=='') {this.value=this.defaultValue;}
	})
		.focus(function() {if(this.value==this.defaultValue) {this.value='';}
	});
	
	
	$('.archive-div').click(function(){
		$(this).hide();
		$('.archive-tbl').show();
	});
	$('.archive-div a').click(function(){
		$(this).parent().parent().click();
		return false
	});

});



indexnavigation = function() {document.onkeydown = NavigateThrough;
function NavigateThrough (event)
    {if (window.event) event = window.event;
	if (event.ctrlKey)
	{
	myHtml = $('#right-cont').html();
	if(myHtml == ''){		
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
		{case 0x25:goPrev();break;}
	} else {
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null){
		case 0x25:goPrev();break;
		case 0x27:goNext();break;
	}}}}}
	
	
subnavigation = function() {document.onkeydown = NavigateThrough;
function NavigateThrough (event) {
	if (window.event) event = window.event;
	if (event.ctrlKey) {
		myHtmlright = $('.job-next').html();
		myHtmlleft = $('.job-prev').html();
			
		if(myHtmlleft == '') {
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null){
			case 0x27:
			window.location = $('.job-next a').attr('href');
			break;}
			} else {
		if (myHtmlright == '') {		
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null){
			case 0x25:
			window.location = $('.job-prev a').attr('href');
			break;} 
			} else {	
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null){
			case 0x25:
			window.location = $('.job-prev a').attr('href');
			break;
			case 0x27:
			window.location = $('.job-next a').attr('href');
			break;}
			}	
			
		}}}}
	
	
	
var arg;
function goPrev()
{
	if ($('.slide').is(":animated")) {} else
	{
		navDirect=-1;
		arg=document.getElementById("goPrev").href;
		InitializeMsgTracker();
		return false;
	}
}

function goNext()
{
	if ($('.slide').is(":animated")) {} else
	{ 
		navDirect=1;
		arg=document.getElementById("goNext").href;
		InitializeMsgTracker();
		return false;
	}
}
var currentJPos=1;
function goCurrent(url,n)
{
    if(currentJPos==n)
    {
        return false;
    }
    if(navDirect==1)
    {
        navDirect=-1;
    }
    else
    {
        navDirect=1;
    }    
//    if(currentJPos>n)
//    {
//        navDirect=1;
//    }
//    else
//    {
//        navDirect=-1;
//    }
    currentJPos=n;
    arg=url;
    InitializeMsgTracker();
	return false;
}

function goPan()
{
		// here call ajax		
		if ($.browser.msie) {
		$("."+inactiveId).css("left",(8500*navDirect)+"px");
		$("."+activeId).animate({ left:(8500*navDirect*(-1))+"px"}, 1500);
		$("."+inactiveId).animate({ left:"0%"}, 1500);
		}
		else {
		$("."+inactiveId).css("left",(350*navDirect)+"%");
		$("."+activeId).animate({ left:(350*navDirect*(-1))+"%"}, 1500);
		$("."+inactiveId).animate({ left:"0%"}, 1500);			
		}

	if(activeId=="slide-1"){
		activeId="slide-2";
		inactiveId="slide-1";
		}else{
		activeId="slide-1";
		inactiveId="slide-2";
		}
		damn_mac_ff();	
		return null;		
	}
var counter=1;
function loadImg()
{
counter++;
}
var msgResponser;

function InitializeMsgTracker()
{
	try
	{
		msgResponser=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			msgResponser=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			msgResponser=null;
		}
	}

	if(!msgResponser&&typeof XMLHttpRequest!="undefined")
	{
		msgResponser=new XMLHttpRequest();
	}
	
	
	var url="/interface/portfolio_index.php?portfolio="+arg;
	if(quick_mode)
	{
	    var url="/interface/portfolio_quick.php?portfolio="+arg;
	}
	
	if(msgResponser!=null)
	{
		//cont.innerHTML='<div class="content"><img src="/i/process.gif" /> Загрузка...</div>';
		msgResponser.onreadystatechange = ProcessMsgResponser;
		msgResponser.open("GET", url, true);
        msgResponser.send(null);
	}
}


function ProcessMsgResponser()
{
if(!msgResponser)return false;
	if (msgResponser.readyState == 4) 
        {
        // only if "OK"
			if (msgResponser.status == 200) 
			{
			   
			   var doc = msgResponser.responseXML;
			   var cNode;
			   goPan();
			   
			   
			   
			   cNode=doc.getElementsByTagName("current")[0];
			   
			   if(activeId!="slide-1")
			   {
					document.getElementById("slide_2").innerHTML=cNode.childNodes[0].data;
			   }
			   else
			   {
					//alert(document.getElementById("slide_1").innerHTML);
					document.getElementById("slide_1").innerHTML=cNode.childNodes[0].data;
					//alert(document.getElementById("slide_1").innerHTML);
			   }
			   
			   cNode=doc.getElementsByTagName("prev")[0];
			   //$("#left-cont").html(cNode.childNodes[0].data);
			   goLeft="";
			   goLeft=cNode.childNodes[0].data;
			   
			   cNode=doc.getElementsByTagName("next")[0];
			   goRight="";
			   goRight=cNode.childNodes[0].data;
			   
			   cNode=doc.getElementsByTagName("class")[0];
			   curclass="";
			   
			   if(cNode.childNodes.length>0)
			   {
			        curclass = "";
			        curclass = cNode.childNodes[0].data;
			   }
			   
			   setTimeout('$("#bg").attr("class",curclass)',1000);
			   if(curclass=="almin-main" || curclass=="ny09-main" || curclass=="almin-main-take7" || curclass=="vetta_liflet" || curclass=="rkg-fs-main" || curclass=="sima-main" || curclass=="technonikol-template-main")
			   {
			        setTimeout("$('#logo img').attr('src','/i/logow.png')",1010);
			   }
			   else if($('#logo img').attr('src')=='/i/logow.png')
			   {
			        setTimeout("$('#logo img').attr('src','/i/logo.png')",1010);
			   }
			   
			   
			   cNode=doc.getElementsByTagName("id")[0];
			   if(cNode!=null)
			   {
			        $('#portfolio-list li').attr("class",'');
			        var icurclass = cNode.childNodes[0].data;
			        $('#p'+icurclass).attr("class",'active');
			   }
			   
			   
			  /*
	           cNode=doc.getElementsByTagName("prevImg")[0];
			   if(cNode.childNodes.length>0)
			   {
			        var i=new Image();
			        i.src=cNode.childNodes[0].data;
			   }*/
			}
		}
}
function goHome()
{
    try
	{
		msgResponser=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			msgResponser=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			msgResponser=null;
		}
	}

	if(!msgResponser&&typeof XMLHttpRequest!="undefined")
	{
		msgResponser=new XMLHttpRequest();
	}
	
	
	
	if(msgResponser!=null)
	{
		//cont.innerHTML='<div class="content"><img src="/i/process.gif" /> Загрузка...</div>';
		msgResponser.onreadystatechange = ProcessGoHome;
		msgResponser.open("GET", "/interface/gohome.php", true);
        msgResponser.send(null);
	}
}

function ProcessGoHome()
{
if(!msgResponser)return false;
	if (msgResponser.readyState == 4) 
        {
        // only if "OK"
			if (msgResponser.status == 200) 
			{
			   window.location.href="/";
			   
			}
		}
}


function flash(url,width,height,id)

{

var bgColor="#ffffff";

document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" align="middle"><param name="allowScriptAccess" value="allways" /><param name="movie" value="'+url+'" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="'+bgColor+'" /><embed src="'+url+'" wmode="transparent" menu="false" quality="high" salign="lt" bgcolor="'+bgColor+'" width="'+width+'" height="'+height+'" name="'+id+'" align="middle"  allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

}

function str_replace(search, replace, subject, count) {
	 var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
			f = [].concat(search),
			r = [].concat(replace),
			s = subject,
			ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}
 
	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') {
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) {
			temp = s[i]+'';
			repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
			s[i] = (temp).split(f[j]).join(repl);
			if (count && s[i] !== temp) {
				this.window[count] += (temp.length-s[i].length)/f[j].length;}
		}
	}
	return sa ? s : s[0];
};

function strstr( haystack, needle, bool ) {
    var pos = 0;
    
    haystack += '';
    pos = haystack.indexOf( needle );
    if (pos == -1) {
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function getscroll(){
	if (self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body){
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
};

