////base.js////

/* jQuery
-------------------------------------------*/

$(function(){

	/* Hover image
	-------------------------------------------*/

	// Arguments are image paths relative to the current page.
	var cache = [];
	$.preLoadImages = function() {  
		var args_len = arguments.length;  
		for (var i = args_len; i--;) {  
			var cacheImage = document.createElement('img');  
			cacheImage.src = arguments[i];  
			cache.push(cacheImage);  
		}  
	}

	// Hover action
	$(function(){
		$("img.hover").mouseover(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_f2$2"));
		}).mouseout(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_f2(\.[a-z]+)$/, "$1$2"));
		}).each(function(){
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_f2$2"));
		})
	});
	
	// Preload image
	$("img.hover").each(function(){
		$.preLoadImages($(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_f2$2"));
	});
	
	/* Link repair
	-------------------------------------------*/
	$("a").each(function() {
		if(!($(this).attr("href"))) {
			$(this).replaceWith($(this).text());
		}
	});	
	
	/* Set corner Desing
	-------------------------------------------*/
	$('.not-front #content h1').corner('3px');
	$('.not-front #content h2').corner('3px');
	$('.not-front #topHeadline h1').uncorner();
	$('.not-front #topProductView h2').uncorner();
	
	/* pngfix
	-------------------------------------------*/
	$('img[src $=.png],.iepngfix').pngfix();

	/* CSS supporter
	-------------------------------------------*/

	// Text margin mandatory control
	$(".not-front #content p + h2").css("margin", "1em 0 0.5em 0");
	$(".not-front #content ul + h2").css("margin", "1em 0 0.5em 0");
	$(".not-front #content div + h2").css("margin", "1em 0 0.5em 0");
	
	$(".not-front #content p + h3").css("margin", "2em 0 0.5em 0");
	$(".not-front #content ul + h3").css("margin", "2em 0 0.5em 0");
	$(".not-front #content div + h3").css("margin", "2em 0 0.5em 0");
	
	/*EXC*/
	$(".not-front #content .noMargin + h3").css("margin", "0 0 0.5em 0");
	
	/* Headline news
	-------------------------------------------*/	
	$(".view-headline-view .view-content").css("overflow","hidden");
	$(".view-headline-view .views-row").css("position","absolute");
	$(".view-headline-view .views-row:not(:first)").hide();
	
	/* Other product mandatory control
	-------------------------------------------*/
	if($("#other_product td .block").size() > 1) {
		$("#other_product td").each(function(){
			if(window.location.href.indexOf($(this).find("a").attr("href")) != - 1) {
				$(this).remove();
			}
		});
	} else {
		$("#other_product").remove();
	}
	
	/* User float img mandatory control
	-------------------------------------------*/
	$("#content img").each(function() {
		
		//alert($(this).attr("style"));
		if($(this).attr("style") == "float: right;" || $(this).attr("style") == "FLOAT: right") {
			$(this).attr("class","img_right");
		}
		if($(this).attr("style") == "float: left;" || $(this).attr("style") == "FLOAT: left") {
			$(this).attr("class","img_left");
		}
	});
	
	/* location path sign
	-------------------------------------------*/
	$("a").each(function(){
		//alert(window.location.href+" / "+$(this).attr("href"));
		if(window.location.href.indexOf($(this).attr("href")) != - 1) {
			$(this).css("font-weight","bold");
		}
	});
	
	/* NotFound rocation
	-------------------------------------------*/
	if($("#content-area").text().match("リクエストされたページが見つかりません。")) {
		document.location = 'http://www.hyogo-bussan.or.jp/';
	}
	
	
	/* Processing on Timeline
	-------------------------------------------*/
	
	// Second-scale interval
	var INTERVAL = 1000 * 1;
	var cnt = 1;
	var acv = 0;
	var size = $(".view-headline-view .views-row").size();
	
	// Timeline
	setInterval(function ()
	{
		//processing
		if(cnt%5==0) {
			if(size == acv+1) {
				$(".view-headline-view .views-row:eq("+acv+")").fadeOut("slow");
				$(".view-headline-view .views-row:eq(0)").fadeIn("slow");
				acv = 0;
			} else {
				$(".view-headline-view .views-row:eq("+(acv+0)+")").fadeOut("slow");
				$(".view-headline-view .views-row:eq("+(acv+1)+")").fadeIn("slow");
				acv++;
			}
		}
		cnt++;
		
	}, INTERVAL);

});
