jsHover = function(id, tag) {
	// run only under IE6
	if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) {
		var hEls = document.getElementById(id).getElementsByTagName(tag);
		for (var i=0, len=hEls.length; i<len; i++) {
			hEls[i].onmouseover=function() { this.className+=" jshover"; }
			hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
		}
	}
}

function prepareImagesClick(elements) {
	jQuery(elements).each(
		function( intIndex ){
			jQuery(this).bind (
				"click", function(){
					popupWindow(this.href);
					return false;
				}
			);
			//jQuery(this).get(0).onclick=null;
		}
	);
}
function getImgSize(imgSrc) {
	var newImg = new Image();
	newImg.src = imgSrc;
	var r = { width: parseInt(newImg.width), height: parseInt(newImg.height) };
	return r;
}
function menuOpen(el) {
	if($($(el).find(".menuOpen_text")[0]).is(":visible")) {
		removeGradientFrom(el);
		$($(el).find(".menuOpen_text")[0]).slideUp("slow", function() {
    		
 		});
		$(el).attr("class", "li_1");
	}	
	else {
		$($(el).find(".menuOpen_text")[0]).slideDown("slow", function() {
    		setGradient();
 		});

		$(el).attr("class", "li_1_active");
		//setGradient();
	}
}
function fix2 () {
		alert(3);
}

function fixHomePage() {
	var maxHeight = 0;
	//alert($(".mainBlock .newsLatest").height() + " - " + $(".opinionsListLatest").height());
	
	if($(".mainBlock .newsLatest").height() < $(".opinionsListLatest").height()) {
		$(".mainBlock .newsLatest").height($(".opinionsListLatest").height());
	}
	else {
		$(".opinionsListLatest").height($(".mainBlock .newsLatest").height());
	}
	//alert(2);
}

function popupWindow(src) {
	
	var maxWidth = 800;
	var maxHeight = 600;
	
	var width = getImgSize(src).width;
	var height = getImgSize(src).height;
	var scrollbars_ = "no";
	
	
	
	if(width >maxWidth) {
		height = parseInt(maxWidth/width * height);
		width = maxWidth;
	
	}
	
	if(height >maxHeight) {
		width = parseInt(maxHeight/height * width);		
		height = maxHeight;
	}
	if(width == 0 && height == 0) {
		width = maxWidth;
		height = maxHeight;
		scrollbars_ = "yes";
	}
	
	var params = 'width=' + width + ',height=' + height + ', scrollbars=' + scrollbars_;
	//alert(width +" "+ height);
	var generator=window.open('','Image',params);
	
	generator.document.write('<html><head><title>Image</title></head>');
	generator.document.write('<body style="background:#eee;margin:0;">');
	generator.document.write('<script>');
	generator.document.write('function getImgSize(imgSrc) {');
	generator.document.write('var newImg = new Image();');
	generator.document.write('newImg.src = imgSrc;');
	generator.document.write('var r = { width: parseInt(newImg.width), height: parseInt(newImg.height) };');
	generator.document.write('return r;}');
	generator.document.write('function resizeWindow(w,h) { if (parseInt(navigator.appVersion)>3) {   if (navigator.appName=="Netscape") {    top.outerWidth=w;    top.outerHeight=h;   }   else top.resizeTo(w,h); }}');
	
	generator.document.write('function fix() {');
	generator.document.write('resizeWindow(getImgSize(document.getElementById("imgPop").src).width,getImgSize(document.getElementById("imgPop").src).height + 80);}');
	generator.document.write('</script>');
	generator.document.write('<a href="javascript:self.close()"><img id="imgPop" src="' + src + '" style="display:block;margin:0 auto;border:0; width:100%" alt="" /></a>');
	generator.document.write('<script>window.onload = function() {fix()}</script></body></html>');
	generator.focus();
	generator.document.close();
}



function getAbsolutePosition(el) {
	
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	r.x = parseInt(r.x);
	r.y = parseInt(r.y);
	return r;
	/*
	Usage:
	document.getElementById('div2').style.left = getAbsPos(document.getElementById('div1')).x + 'px';
	document.getElementById('div2').style.top = getAbsPos(document.getElementById('div1')).y + 'px';
	*/	
}

function removeGradientFrom(el) {
	$(el).find(".gradient_").remove();
	$(el).find(".gradient__").remove();
}
function removeGradient() {
	$('.gradient_').remove();
	$('.gradient__').remove();
}
function setGradient() {
	removeGradient();
	
	fixHomePage();
	
	$('.gradient').gradient({
		from:      'ffffff',
		to:        'f3f3f4',
		direction: 'horizontal'
	});								
	$('.block1 .content').gradient({
		from:      'ffffff',
		to:        'f3f3f4',
		direction: 'horizontal'
	});
	$('.block2 .content').gradient({
		from:      'ffffff',
		to:        'f3f3f4',
		direction: 'horizontal'
	});
	$('.block3').gradient({
		from:      'ffffff',
		to:        'f3f3f4',
		direction: 'horizontal'
	});
	
	$('.gradient').gradient({
		from:      'ffffff',
		to:        'f3f3f4',
		direction: 'horizontal'
	});
	$('.csc-textpic-caption').gradient({
		from:      'f3f3f4',
		to:        'ffffff',
		direction: 'horizontal'
	});
	
	prepareImagesClick(".review_list .img a");
	prepareImagesClick(".review_list .image a");
	prepareImagesClick(".interview_list .image a");
	prepareImagesClick(".project_list .img a");
	
	
	
}
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = jQuery(this).height();		
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

