/*==============================================
 checkjs
==============================================*/
$(function(){
	$('body').removeClass('nojs');

tweetRepeat();
twitPost();
sidebarHeightFix();


});

function tweetRepeat(){
	var $tweet  = $('#tweetRepeat'),
	    $tweets = $tweet.find('li'),
	    current = 0,
	    maxnum  = $tweets.length-1;
	$tweets.each(function(i){
		if(i > 0){
			$(this).css({opacity:0, position:'absolute'}).hide();
		} else{
			$(this).addClass('current');
		}
	});
/*
	var tId = setInterval(function(){
		var nextItem = '';
		var nextNum  = 0;
		if(current+1 <= maxnum){
			nextItem = $tweets.eq(current+1);
			nextNum  = current+1;
		} else {
			nextItem = $tweets.eq(0);
			nextNum  = 0;
		}
		$tweets.filter('.current').animate({opacity:0},'slow',function(){$(this).hide(); current=nextNum;});
		nextItem.addClass('current').animate({opacity:100},'slow',function(){$(this).show();});
	},11000);
*/
}

function twitPost(){
	var $twitPost  = $('#m_twitter_post'),
	    $textarea  = $('textarea',$twitPost),
	    $submitBtn = $('input.button',$twitPost);
	$submitBtn.click(function(){
		var text = $textarea.val();
		var url  = 'http://twitter.com/home?status='+encodeURIComponent(text);
		window.open(url);
		return false;
	});
}

function sidebarHeightFix(){
	var $mainCol = $('div.main'),
	    $subCol = $('div.sub');
	var mainHeight = $mainCol.outerHeight(),
	    subHeight  = $subCol.outerHeight();
	while(subHeight > mainHeight){
		$('#s_books div.article:last').remove();
		mainHeight = $mainCol.outerHeight();
		subHeight  = $subCol.outerHeight();
		if($('#s_books div.article:last').length < 1){
			$('#s_books p.ttl').remove();
			break;
		}
	}
}

function buttonFix(){
	$('input.button').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).addClass('remove');
	});
}


/*==============================================
 easily RollOver
==============================================*/
$.fn.imageRollOver = function(){
	var obj = obj || {};
	$(this).each(function(){
		var src  = this.src;
		var osrc = src.replace("_off.","_on.");
		obj[src] = new Image();
		obj[src+"_d"] = new Image();
		obj[src].src = osrc;
		obj[src+"_d"].src = src;
		$(this).hover(function(){
			if(!$(this).hasClass('current'))
				this.src = obj[src].src;
		},function(){
			if(!$(this).hasClass('current'))
			this.src = obj[src+"_d"].src;
		})
	})
}
$(function(){$("img[src*='_off.'],input[src*='_off.']").imageRollOver();});


/*==============================================
 IE bgfix
==============================================*/
try{document.execCommand("BackgroundImageCache", false, true);} catch(e){}

