$(function() {
		var lines = $("#home_page_ship span.line"),
			img = ("#home_page_ship img"),
			text = [
				["<strong>- - - - - - -</strong>", "* * * * * *"],
				["<strong>&lt; &lt; &lt;</strong>", "- - - - - - -"],
				["<strong>:-) :-( %-)</strong>","^_^ -_- ^_^"],
				["—","<strong>^^^^^</strong>","⌂┐⌂┐⌂"],
				["|||╓╓╓╓","—","<strong>│││╕╕╕╕</strong>"],
				["<strong>- - - - - - -</strong>", "* * * * * *"]			
				],
			old_text = [];

	var home_page_ship = $("#home_page_ship");
	
	/* text_shape */
	text_shape_css = ['.shape_text i{ display:block; height:1.27em; width:0; position:relative; }',
					'body .lightBlock .shape_text i{ height:1.4em; }',
                    '.shape_text i.l{ float:left; clear:left; }',
                    '.shape_text i.r{ float:right; clear:right; }'].join('');
	
/*	$("#lCol").css({width:'60%', marginRight:'-15%', position:'relative'});
	$("#rCol").css({width:'60%', marginRight:'-15%', position:'relative'});
*/	
	text_shape($("#lCol"), {
		f1:function(t, y){
			return y*0.4;
		},
		f2:function(t, y){
			//r = 100 - t*100;
			return 200*(1-t);
		},
		cssText:text_shape_css
	});
	
	text_shape($("#rCol"), {
		f1:function(t, y){
			return y*0.4;
		},
		cssText:text_shape_css
	});
	
	function text_shape_bind() {
		window.lCol_width = $("#lCol").width();
		window.rCol_width = $("#rCol").width();
		
		$("#lCol, #rCol").removeClass('lightBlock');
		text_shape($("#lCol")).create();
		text_shape($("#rCol")).create();
	}
	
	text_shape_bind();
	jCommon.measurer.bind(text_shape_bind);

	lines.each(function(i, val) {
		old_text[i] = [];
		var old = $(this).children().each(function(){
			old_text[i].push($(this).html());
		});
		old_text[i] = old_text[i].reverse();
	});
	
	
	function addWord(){
		if(window.wordAnimated !== 1) {
			window.wordAnimated = 2;
			window.wordCounter = window.wordCounter ? window.wordCounter : [];
			lines.each(function(i, val){
				window.wordCounter[i] = window.wordCounter[i] ? (window.wordCounter[i] == text[i].length ? 0 : window.wordCounter[i]) : 0;
				var t = $(this).text();
				//$(this).children('span').slice(3).remove;
				/*
				if(t.length > 1000) $(this).text(t.substr(0, 600));*/
				var s = document.createElement("span");
				s.className = 'fake';
				s.innerHTML = text[i][window.wordCounter[i]++]+'<strong class="sep"> </strong>';
				$(this).prepend(s);
				//this.innerHTML = text[i][window.wordCounter[i]++]+'<strong> </strong>'+this.innerHTML;
			})
			window.wordTimer = setTimeout(addWord, 100)
		}
	}

	function returnWord(){
		clearTimeout(window.wordTimer);
		$('span.fake', lines).animate({marginLeft:1500}, 4000, function(){ $(this).remove(); });;
		window.wordAnimated = 1;
		window.wordCounter = window.wordCounter ? window.wordCounter : [];
		window.wordAnimatedString = window.wordAnimatedString ? window.wordAnimatedString : [];
		lines.each(function(i, val){
			window.wordCounter[i] = window.wordCounter[i] ? window.wordCounter[i] : 0;
			if(old_text[i][window.wordCounter[i]]) {
				window.wordAnimatedString[i] = 1;
				var s = document.createElement("span");
				s.innerHTML = old_text[i][window.wordCounter[i]++]+'<strong class="sep"> </strong>';
				$(this).prepend(s);
			} else {
				window.wordAnimatedString[i] = 0;
			}
		});
		if(parseInt(window.wordAnimatedString.join('')) !== 0) {
			window.wordTimer = setTimeout(returnWord, 80);
		} else {
			clearTimeout(window.wordTimer);
			window.wordAnimated = 0;
			window.wordCounter = [];
		}
	}
	
	function prevent(e){
		e.preventDefault();
	}
	
	home_page_ship.hover(
		function() {
			window.wordStartTimer = setTimeout(addWord, 600);
		},
		function() {
			clearTimeout(window.wordStartTimer);
			if(window.wordAnimated === 2) {
				window.wordCounter = [];
				window.wordAnimatedString = [];
				window.wordFake = lines.wrapInner("<span class='fake'></span>");
				returnWord();
			}
		}
	)
});


$(document).ready(function(){
	$("#lCol").mouseover(function(){
		clearTimeout ( changeTimerId );
		$("#lCol").addClass('lightBlock');
		$("#rCol").removeClass('lightBlock');
	});

	$("#lCol").mouseout(function(){
		startBlockStyleTimer();
	});

	$("#rCol").mouseover(function(){
		clearTimeout ( changeTimerId );
		$("#rCol").addClass('lightBlock');
		$("#lCol").removeClass('lightBlock');
	});
	
	$("#rCol").mouseout(function(){
		startBlockStyleTimer();
	});
	
	changeTimerId = startBlockStyleTimer();
});

startBlockStyleTimer = function(){
	var delaytime = 5000;
	changeTimerId = setTimeout(changeBlockStyle, delaytime);
	return changeTimerId;
}

changeBlockStyle = function(){
	if($("#lCol").attr('class') == "clmn"){
		$("#lCol").addClass('lightBlock');
		$("#rCol").removeClass('lightBlock');
	}else{
		$("#rCol").addClass('lightBlock');
		$("#lCol").removeClass('lightBlock');
	}
	startBlockStyleTimer();
}

