$(document).ready(function(){
	var projectsDropDownOpen = false;
	$("div.projects-selector li.item").mouseover(function(){
		$(this).addClass('hover');
	});
	$("div.projects-selector li.item").mouseout(function(){
		$(this).removeClass('hover');
	});		
		
	$("div.projects-selector label,div.projects-selector button").click(function(){
		if (projectsDropDownOpen) {	
			$("div.projects-selector div.projects-dropdown").slideUp();
		} else {
			$("div.projects-selector div.projects-dropdown").slideDown();
		}
		projectsDropDownOpen = !projectsDropDownOpen;
	});
	
	$("div.projects-selector li.item").click(function(){
		$("div.projects-selector input").val($(this).children("span").html());
		window.location.href = $(this).children("span").attr("href");
		$("div.projects-selector div.projects-dropdown").hide();		
		projectsDropDownOpen = false;
	});
	
	//setInterval('rotateCamera()', 500);	
});

var cameraBasedir = '/sites/all/themes/lean_ru_smarty/design/camera/';
function preloadCameras () {
	_c = new Array();
	for (i = 0; i < 5; i++) {
		$(document.createElement('img')).bind('load', function(){
			this.src = cameraBasedir + i + '.jpg';
		}).trigger('load'); 
	}
}

var	cameraNum   = 0;
var cameraDelta = 1;
function rotateCamera () {
	cameraNum = (cameraNum + cameraDelta);
	if (cameraNum % 4 == 0) {cameraDelta = -cameraDelta;}
	$('#camera, #sidebar-left').css('background-image', 'url(' + cameraBasedir + cameraNum + '.jpg)');
}

function imgOpen(imgLink,Title,width,height) {
	var doResize;
	if (width == null) {width = 100;height = 100;doResize=1}
  if (typeof(window.resizeBy)=='undefined') return true;
  imgWndw=window.open('',imgLink.target,'width='+width+',height='+height+
    ',toolbar=no,menubar=no,location=no,status=no,'+
    'resizable=yes,scrollbars=no,left='+(screen.width>>>2)+
    ',top='+(screen.height>>>4));
  if (doResize) self.focus();
  var imgTitle=(Title)?Title:imgLink.href;
  with (imgWndw.document){
    open();
    write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
    '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+
    'rightmargin="0" bottommargin="0" marginwidth="0" '+
    'style="margin:0;padding:0;position:fixed;overflow:none;" '+
    'marginheight="0"><img src="'+imgLink.href+'" border="0" '+
    ' alt="'+imgTitle+'" title="'+imgTitle+'"/></bo'+
    'dy></ht'+'ml>');
    close();
  }
  if (doResize==1) {resId=setInterval('imgResize()',500);}
  return false;
}

function imgResize() {
  var w=imgWndw.document.images[0].width;
  if (w>screen.availWidth) w=screen.availWidth;
  var h=imgWndw.document.images[0].height;
  if (h>screen.availHeight) h=screen.availHeight;
  if (w>50 && h>50) {
    var ww=(imgWndw.innerWidth)?imgWndw.innerWidth:((document.body)?
      imgWndw.document.body.clientWidth:null);
    var wh=(imgWndw.innerHeight)?imgWndw.innerHeight:((document.body)?
      imgWndw.document.body.clientHeight:null);
		if (/gecko/i.exec(navigator.userAgent)) ww-=50;
    if (ww && wh) {
      imgWndw.resizeBy(w-ww,h-wh);
    }
    imgWndw.focus();
    clearInterval(resId)
  }
}

function loadFlash (src, width, height) {
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', (width ? width : 460),
			'height', (height ? height : 380),
			'src', src,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', '_flash',
			'bgcolor', '#ffffff',
			'name', '_flash',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','sameDomain',
			'movie', src,
			'salign', '',
			'flashvars', ''
			); //end AC code
	};
}