$(document).ready(function(){

	/*初期設定*/
	var url="http://www.tapommes.com",
		$isiPhone = navigator.userAgent.indexOf('iPhone');
	
	/*ロード*/
	setTimeout(showheader,1000);
	setTimeout(showslideshow,1000);
	setTimeout(showmonthblock,3000);
	setTimeout(showcontainer,4000);
	
	$("div#slideshow div").slideshow();
	
	/*クラス追加*/
	if($isiPhone = -1 ){
		$("div#container div#pickuptop h1,div#container div#righttop h1,div#container div#sidebar h1,div#container div#left h1,div#container div#right h1,div#container div#category h1").addClass("jgif");
	}
	
	/*ロゴ画像置換*/
	$(".jpng").jQIR("png", url+"/wp-content/themes/ruedelapomme/images/");//png、imageフォルダの指定
	$(".jjpg").jQIR("jpg", url+"/wp-content/themes/ruedelapomme/images/");//jpg
	$(".jgif").jQIR("gif", url+"/wp-content/themes/ruedelapomme/images/");//gif
	
	/*ロゴマウスオーバー*/
	$("#header div.left a#logo").hover(
		function(){$(this).animate({opacity:"0.5"},500)
		},
		function(){$(this).animate({opacity:"1"},500)
		});

	$('div.execphpwidget,div.textwidget').each(function(){
		$(this).replaceWith($(this).html());
	});

	/*画像マウスオーバー*/
	$("div#container")
		.find("div#pickuptop a.photo, div#pickuptop a.jjpg, div.icon a.photo, div.pickup a").hover(
		function(){$(this).animate({opacity:"0.5"},500)
		},
		function(){$(this).animate({opacity:"1"},500)
		});
	
	/*その他*/
	$("div#monthblock div .nostyle,#container .links h3,#container .sweetindex h3").remove();
	$("div.links ul li:last-child").css("border-bottom","1px solid #eee");
	$("div#container div div.post p a:first, div.sweets p a:first, div.sweetindex ul li a:first").addClass("first");
	$("div#container div div.post p a:odd, div.sweets p a:odd, div.sweetindex ul li a:odd").addClass("odd");
	$("div#container div div.post p a:last, div.sweets p a:last, div.sweetindex ul li:last, div.sweetindex ul li a:last").addClass("last");
	$("div.sweets p:even").addClass('even');
	$("div.sweets p:odd").addClass('odd');
    
	/*アイコンマウスオーバー*/
	$("div.icon a").hover(
		function(){$(this).animate({opacity:"0.5"},500)
		},
		function(){$(this).animate({opacity:"1"},500)
		});

	/*外部リンク*/
	$('a[@href^="http"]').not('[@href*="www.tapommes.com"]').not('[href^=#]').click(
		function(){window.open(this.href,'_blank');
		return false;
		});

});

function showheader(){
	$("div#header")
	.animate({
		filter:"alpha(opacity=100)",
		opacity:"1"
	},"slow");
};

function showslideshow(){
	$("div#slideshow")
	.animate({
		filter:"alpha(opacity=100)",
		opacity:"1"
	},"slow");
};

function showmonthblock(){
	$("div#monthblock")
	.animate({
		filter:"alpha(opacity=100)",
		opacity:"1"
	},"slow");
};

function showcontainer(){
	$("div#container")
	.animate({
		filter:"alpha(opacity=100)",
		opacity:"1"
	},"slow");
};

$.fn.slideshow = function(options){
	//デフォルト値設定
	var defaults = {
		speed:4000,
		timeOut:7000
	};
	//オプションの初期値設定
	var setting = $.extend({}, defaults, options);
	
	// セレクタで指定した要素を処理
	this.each(function(){//thisを一つずつ処理
		var $element = $(this);
		$element.children(':gt(0)').hide();
		setInterval(function(){
			$element.children().eq(0).fadeOut(defaults.speed)
			.next().fadeIn(defaults['speed'])
			.end().appendTo($element);
		}, defaults.timeOut);
	});
	return this;//メソッドチェインのための記述
}
