/*if (/MSIE (5\.5|6)/.test(navigator.userAgent)) {
	document.write("<scri"+"pt src='/js/iepngfix_tilebg.js'></scr"+"ipt>");
}*/



$(function(){
	$("#nav li img,li#blog img").scgrph_swapper();
	if(location.pathname!="/") $("#nav li img:first").scgrph_swapper({force:"inactive"});
	$("#sub-nav li img:not(:first)").scgrph_swapper();
	$(".snav li img").scgrph_swapper();
//	$("#header li:eq(1)").hide();
	
	
	
	if(location.pathname!="/"){
		$.ajax({url:"/proxy.php",dataType:"json",success:function(o){
			$.each(o,function(){
				var line = this["title"];
				$('<div style="font-size:11px;line-height:1.1;oveflow:hidden;width:192px;height:2.2em;"><a href="'+this["link"]+'" target="_blank" title="'+line+'" >'+this["date"]+"<br>"+line+'</a></div>').appendTo("#quick-link li:first");
				return false;
			});
		}})
		$.ajax({url:"/proxy.php?from=mixed",dataType:"json",success:function(o){
			$.each(o,function(){
				var line = this["title"];
				$("p:first").after('<div style="font-weight:normal;font-size:11px;line-height:1.1;oveflow:hidden;width:400px;padding:4px;text-align:right;position:absolute;right:0;" id="ticker"><a href="'+this["link"]+'"  title="'+line+'" style="text-decoration:none;color:#6595C5;">'+this["date"]+" "+line+'</a></div>');
				$(window).trigger("resize");
				return false;
			});
		}})
	}
	
	$(window).resize(function(){
		$("#header p").each(function(){$(this).css("left",parseInt(($(window).width()-$(this).parent().width())/2+($(this).parent().width()-$(this).width()))+"px")});
		$("#ticker").each(function(){$(this).css("left",parseInt(($(window).width()-$(this).parent().width())/2+($(this).parent().width()-$(this).width()))+"px").css("top",$("#header p").height()+"px")});
	}).trigger("resize");
	
	
	var BP = "/";
	if(location.href.indexOf("contact")>-1 /*|| 
	   location.href.indexOf("addchange")>-1 ||
	   location.href.indexOf("app.php/contact")>-1 || 
	   location.href.indexOf("app.php/research")>-1 */
	){
		$("#nav li img:last").scgrph_swapper({force:"active"});
		
		$.scgrph_import(BP+"js/jquery.simplemodal-1.1.1.min.js",BP+"js/jquery.cake_form.js",BP+"js/jquery.form.js",function(){//alert(1);
			$("#content form").form_validation({callback:function(m){//console.log(m);
				var html = "<ul>";
				$(m).each(function(){
					html += "<li>"+this+"</li>";
				});
				html += "</ul>";
				$.modal("<h2>以下項目を正しくご入力ください</h2>"+html+"<div style=text-align:center><a href='#' onclick='javascript:try{$.modal.close();$(\".has-error\").get(0).focus();$(\".has-error\").get(0).select();}catch(e){};return false;'>閉じる</a></div>"
				,{overlay:10});
			},
			loading:function(){
				$.modal("お待ちください...",{overlay:10,containerCss:{border:"solid 3px #ccc",padding:"10px",height:"100px"}});
			},
			onLoad:function(){
				$.modal.close();
			}
			
			});
		});
		
	}


});

