$(document).ready(function(){
/////////////////// START ///////////////////

//DOM reload & start
function StartFunctionsAll(){
	LightBox();
	HrefLightBox();
	ModalContact();
	ModalContactGET();
	TwitterPosts();
	//setEqualHeight($('#Notice > div'));
	validateColumm();
	PicasaAlbum();
	FindPicasa();
	Twitter();
	Nofollow();
	Share();
}
StartFunctionsAll();

//Twitter
function Twitter(){
	$('.Tweets').tweet({join_text: '⇄',	username: 'wearymax',count: 7,loading_text: 'Подключение к API...'});
	setTimeout(Nofollow, 1500);
}
//Picasa
function FindPicasa(){
	if ($('#Page').find('#Picasa').length == 0) {
		//no found
	} else {
		$("#Picasa").Picasa('wearymax');
	}
}
//Portfolio Carusel
$('.Carusel').scrollable({circular: true, mousewheel: true}).navigator().autoscroll({interval: 5000});
//Add Active Class in Menu
var path = window.location.pathname;
var current = window.location.pathname.split("/")[1];
if(window.location.pathname.length <= 1) {
	//none
} else {
	var url = current,
	urlRegExp = new RegExp(url.replace(/\/$/,''));
	$('UL.Cetegories > li > a').each(function(){
		if(urlRegExp.test(this.href)){
			$(this).addClass('Active');
		}
	});
}
//Logo href
$("#Header .Logo").click(function(){
	window.location = '/';
    return false;
});
$("#Header .Logo").fadeTo(300, 0.9);
$("#Header .Logo").hover(function() {
	$(this).stop().fadeTo(300, 1);
	}, function(){
	$(this).stop().fadeTo(300, 0.9);
});
//Auto height collums
function setEqualHeight(columns) {
	var tallestcolumn = 0;
	columns.each(function(){currentHeight = $(this).height(); 
	if(currentHeight > tallestcolumn) {tallestcolumn  = currentHeight;}});
	columns.height(tallestcolumn);
}
//Remove empty DIV
function validateColumm() {
	if($.trim($('#Infoblock').text()) == "") {
		$('#Infoblock').remove();
	} else {
		$('#Content').addClass('Left');
	}
}
//LightBox
function HrefLightBox() {
	$("a[class^='lightbox']").lightbox();
	//All params - http://s3.envato.com/files/1099520/index.html
}
//Share BTN
function Share(){
	var URL = window.location;
	var TITLE = $('title').text();
	$('#Footer').prepend('<div id="Share"><a href="http://twitter.com/?status='+TITLE+'%20&mdash;%20'+URL+'" target="_blank" title="Написать в Twitter"><img src="/style/share1.png"></a>'
	+'<a onClick="window.open(\'http://vkontakte.ru/share.php?url='+URL+'&amp;title='+TITLE+'\',\'\',\'width=800,scrollbars=no,status=no,resizable=1\')" title="Разместить Вконтакте"><img src="/style/share2.png"></a>'
	+'<a href="http://www.facebook.com/share.php?u='+URL+'" target="_blank" title="Разместить в Facebook"><img src="/style/share3.png"></a>'
	+'<a href="http://connect.mail.ru/share?share_url='+URL+'" target="_blank" title="Отправить ссылку в Мой.Мир"><img src="/style/share4.png"></a>'
	+'<a href="http://www.livejournal.com/update.bml?subject='+TITLE+'&amp;event='+URL+'" target="_blank" title="Запостить в ЖЖ"><img src="/style/share5.png"></a>'
	+'<a href="http://my.ya.ru/posts_add_link.xml?title='+TITLE+'&amp;URL='+URL+'" target="_blank" title="Поделиться ссылкой на Я.ру"><img src="/style/share6.png"></a></div>');
}
//FUCK MSIE
if ($.browser.msie) {
	window.location = /msie/;	
};

//Mobile fix
if ((navigator.userAgent.match(/iPhone/i)) || 
	(navigator.userAgent.match(/iPod/i)) || 
	(navigator.userAgent.match(/iPad/i)) || 
	(navigator.userAgent.match(/android/i)) || 
	(navigator.userAgent.match(/Opera Mobi/i)) || 
	(navigator.userAgent.match(/Opera Mini/i)) || 
	(navigator.userAgent.match(/symbian/i)) ||  
	(navigator.userAgent.match(/blackberry/i))) {
	addEventListener("load", function() {
	//Menu Mobile
	$('ul.Cetegories > li').hover(function() {	
		if($.trim($('ul', this).text()) == "") {
  			$('ul', this).remove();
	}            
		if ($(this).find('ul').length == 0) {
		//no found
		} else {
			$(this).find('ul').stop(true, true);
			$(this).find('ul').fadeIn(1000);
		}            
			$('a',this).addClass('Sel');
	}, function(){
		$(this).find('ul').fadeOut(1000); 
		$('a',this).removeClass('Sel');
	});
	//WMODE Param Mobile
	$('EMBED, OBJECT, IFRAME').attr({'width':'100%'}).attr({'height':'auto'});	
		setTimeout(hideURLbar, 10);
		function hideURLbar(){window.scrollTo(0, 1);}							
	}, false);
} else {
	//Airport 
	$('#Airport').flightboard({
		messages: ['ОСНОВНЫЕ УСЛУГИ:','1-РАЗРАБОТКА САЙТОВ','2-USABILITY ТЕСТЫ','3-ПРОЕКТИРОВАНИЕ UI','4-ОПТИМИЗАЦИЯ','5-АНАЛИТИКА','6-ФОТОСЪЕМКА','ИНТЕРЕСНЫЕ ЦЕНЫ!','ПАРТНЕРАМ: 10%','@WEARYMAX'],
		lettersSize: [45, 70],
		maxLength: 19,
		flips: [3, 10],
		lettersSeq: ' ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ0123456789-+:!?@#%',
		speed: 100,
		pause: 3000,
		opacity: 0.5,
		lettersImage: '/style/Alphabet.png'
	});	
	//Menu
	$('ul.Cetegories > li').hover(function() {	
		if($.trim($('ul', this).text()) == "") {
	  		$('ul', this).remove();
		} else {
			$(this).find('ul').stop().fadeTo(300, 0.9).prepend('<li class="Arrow"><div>&#9650;</div></li>');		
		}            
		$('a',this).addClass('Sel');
	}, function(){
		$(this).find('ul > li.Arrow').remove();
		$(this).find('ul').hide(); 
		$('a',this).removeClass('Sel');
	});
	//WMODE Param
	$('EMBED, OBJECT').attr({'width':'600px'}).attr({'height':'370px'}).attr({'wmode':'transparent'});
	}	
	//rel=nofollow auto
	function Nofollow(){
	$('a').each(function() { 
		var href = jQuery(this).attr('href');
	    if (typeof href != 'undefined' && href != "" && (href.indexOf('http://') != -1 || href.indexOf('https://') != -1) && (href.indexOf(window.location.hostname) == -1 || href.indexOf(window.location.hostname.replace('www.', '')) == -1 ) == -1) {
	    	$(this).attr("rel", "nofollow").attr("target", "_blank");
	    }
	});
}
//END Mobile fix

/////////////////// END ///////////////////
});

//Mobile detector CSS
if(	(navigator.userAgent.match(/iPhone/i)) || 
	(navigator.userAgent.match(/iPod/i)) || 
	(navigator.userAgent.match(/iPad/i)) || 
	(navigator.userAgent.match(/android/i)) || 
	(navigator.userAgent.match(/Opera Mobi/i)) || 
	(navigator.userAgent.match(/Opera Mini/i)) || 
	(navigator.userAgent.match(/symbian/i)) ||  
	(navigator.userAgent.match(/blackberry/i)) ){
	document.write("<link type='text/css' rel='stylesheet' media='all' href='/style/mobile.css'/>");
	document.write("<meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no;'/>");
} else {
	document.write("<link type='text/css' rel='stylesheet' href='/style/main.css'/>");
}
	document.write("<link rel='alternate' type='application/rss+xml' title='WearyMax RSS' href='/news/rss'/>");
