/*
 *	Mediahead content positioning v.1.0
 *
 *	Copyright 2010, "Mediahead"
 *	info@mediahead.ru
 *	www.mediahead.ru
 *
 *	Copyright 2010, Mikhail Pashin
 *	misha@mishapashin.com
 *	www.mishapashin.com
 *
 */

$(document).ready(function(){
	contentSize();
	$("#bg").mediaheadResizer();
	posEl();
	request();
	form();
});

$(window).load(function(){
	posEl();
	posEl();
});

$(window).bind("resize",function(){
	$("#bg").mediaheadResizer();
	contentSize();
	return this;
});

$.fn.mediaheadResizer = function(){
	var ratio = 900 / 1280;
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();

	if ((windowHeight/windowWidth) > ratio){
		$(this).height(windowHeight);
		$(this).width(windowHeight / ratio);
	} else {
		$(this).width(windowWidth);
		$(this).height(windowWidth * ratio);
	}
	
	$(this).css("left", (windowWidth - $(this).width()) / 2);
	$(this).css("top", (windowHeight - $(this).height()) / 2);
	return this;
};

function posEl() {
	var mediaCo1 = $(".mediaAll .clientsPartners:first").width();
	var mediaCo2 = $(".mediaAll .clientsPartners:last").width();
	$(".mediaAll").css("width",(mediaCo1 + mediaCo2) + 180);
}

function contentSize() {
	var docW = $(document).width();
	var docH = $(document).height();
	
	if (docW > 1400 && docH > 700){
		$(".contentLeftA p").css("font-size",18);
		$(".text h1").css({"font-size":38,"marginBottom":40});
		$(".rightMenu ul li").css("font-size",22);
		$(".rightMenu .level li").css("font-size",18);
	} else {
		$(".contentLeftA p").removeAttr("style");
		$(".text h1").removeAttr("style");
		$(".rightMenu ul li").removeAttr("style");
		$(".rightMenu .level li").removeAttr("style");
	}
}

function request() {
	$(".offer a").toggle(
		function() {
			$(this).addClass("active");
			$(".form").show();
			$(".close").show();
			$(this).text("X Закрыть");
		},
		function() {
			$(this).removeClass("active");
			$(".form").hide();
			$(".close").hide();
			$(this).text("Оставить заявку");
	});
}

function form() {
	$('input[type="text"]').focus(function() {
		if (this.value == this.defaultValue){
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});

	$('input[type="text"]').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});		

	$('textarea').focus(function() {
		if (this.value == this.defaultValue){
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});

	$('textarea').blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
}
