
/**
 * QUINO INCORPORATED
 *
 * Javascript
 *
 * copyright Copyright (C) 2009 qui-no, Inc. All Rights Reserved.
 */

/**
 * swap()
 *
 * param String afterString
 * retun void
 */
function swap(afterString) {

	var imgCache = new Object();
	$('img.swap').each(function(i) {
        var src  = this.src;
        var dot  = src.lastIndexOf('.');
        var over = src.substr(0, dot) + afterString + src.substr(dot);

		imgCache[i] = new Image();
        imgCache[i].src = over;

		$(this).hover(
            function() { $(this).attr('src', over) },
            function() { $(this).attr('src', src) }
		);
    });
}

/**
 * loadImage()
 *
 * param String id
 * param Object attr
 * return Image|null
 */
function loadImage(id, attr) {

	if (1 > $(id).length) {
		return null;
	}

	var image = new Image();
	$(image).load(function() {
		$(this).hide();
		$(id).removeClass('loading').prepend(this);
		$(this).show();
	});

	$.each(attr, function(key, value) {
		$(image).attr(key, value);
	});

	return image;
}

/**
 * loadIndexVisual()
 *
 * return void
 */
function loadIndexVisual() {

	if (1 > $('#index-visual').length) {
		return;
	}

	var image = new Image();
	$(image).load(function() {
		$(this).hide();
		$('#index-visual').removeClass('loading').prepend(this);
		$(this).show();
		$('#index-visual-link').show();
	}).attr('id', 'index-visual-img')
	.attr('src', 'common/images/top.gif')
	.attr('alt', 'AD ticker - RSSティッカー型デスクトップメディア広告配信：フィードや広告などをユーザーのデスクトップへ表示する“デスクトップ受信機能”と、配信情報を管理する“配信サーバ管理機能”を提供するシステムです。');
}

// Document Ready
$(function() {

	// Index image loading
	loadIndexVisual();

	// Swap image
	swap('_over');

	// Page scroll
	$('#pagetop').click(function() {
        $('html,body').animate({ scrollTop: 0 }, 400, 'easeOutQuart');
    });
});
