/**
 * @author <a href="http://meia5.com">Media5</a> - <a href="mailto:banzalik@media5.com">Бойченко Александр</a>
 * @description скрипты для m5 css framework
 */
 
 /**
 * @description полная загрузка страницы, картинки при этом уже загрузились
 */
window.onload=documentLoaded; // присваиваем функцию documentLoaded

/**
 * @description вызов функций при полной загрузке страницы, картинки при этом уже загрузились
 */
function documentLoaded(){
	
}


/**
 * @description вызов функций при полной загрузке DOM дерева, картинки при этом еще не загрузились
 */
$(document).ready(function(){
			autoclearInput();
			//formChek();
})


/**
 * @description очистка инпутов, при клике на них
 */
function autoclearInput(){
	$(".autoclear").each(function(){
		$(this).attr("defaultvalue",$(this).attr("value")); // записываем в defaultvalue значение по умолчанию, необходимо для проверки нового стекста со старым
	});

	$(".autoclear").click(function(){ 
		if ($(this).attr("value")==$(this).attr("defaultvalue")) { // проверяем совпадают ли value и defaultvalue
			$(this).attr("value", ""); // сбрасываем значение value
		}
	})
}

/* poup */
function popup (lang) {
	$("#popupShadow").click(function () { 
									  popupClose ();
	  });
	// show shadow
	var shadowSize=getPageSize();
	$("#popupShadow").height(shadowSize[1]);
	$("#popupShadow").show();
	$("#"+lang).show('normal');
	if ($("#"+lang).offset().top <0) { $("#"+lang).css({ "position":"absolute", "margin-top":0, "top":0})}
	if ($("#"+lang).offset().left <0) { $("#"+lang).css({ "position":"absolute", "margin-left":0, "left":0})}
	
}

function popupClose (){
      $("#popupShadow").slideUp();
	$(".popup").hide('normal');
	
}


function  getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

