$(document).ready(function(){
	jQuery.ifixpng('img/pixel.gif');
	jQuery('img[src$=png]').ifixpng();
	
	sifr();
	initPage();
		
	$("#logo").hover(function() {
    //$(this).css("top", "2px");		
    $(this).stop().animate({'top': '2px'},"normal");
  }, function() {
		//$(this).css("top", "-12px");				
		$(this).stop().animate({'top': '-8px'},"normal");	
  });	
	
	
	$("#nav a img").hover(function() {
    $(this).attr("src", $(this).attr("src").split("_off.").join("_on."));		
  }, function() {
		if(!$(this).parent().parent().hasClass("current")){
			$(this).attr("src", $(this).attr("src").split("_on.").join("_off."));
		}					
  });	
	$("#tools a img").hover(function() {
    $(this).attr("src", $(this).attr("src").split("_off.").join("_on."));		
  }, function() {
		if(!$(this).parent().hasClass("current")){
			$(this).attr("src", $(this).attr("src").split("_on.").join("_off."));
		}					
  });
	$("#nav li.current").children("ul").css("left", "0px");


	$("#nav li").hover(function(){		
		if(this.className.indexOf("current") == -1)  {
			var getCurrent = $(this).parent().children("li.current:eq(0)");			
			var el = $(this);
			if (getCurrent = 1 ) {
				$(this).parent().children("li.current:eq(0)").children("ul").hide();
			}		
			$(this).children("ul:eq(0)").css("left", "0px").animate({'opacity': 1},"normal");
		}
	},function(){
		if(this.className.indexOf("current") == -1)  {
			var el = $(this);
			var getCurrent = el.parent().children("li.current:eq(0)");
			if (getCurrent = 1 ) {
				$(this).parent().children("li.current:eq(0)").children("ul").show();
			}
			$(this).children("ul:eq(0)").css("left", "-99999px").css('opacity', 0);
		}
	});
	
	$("img.teaserimg").hover(function() {
    $(this).attr("src", $(this).attr("src").split(".").join("_ro."));		
  }, function() {
		$(this).attr("src", $(this).attr("src").split("_ro.").join("."));
  });
	
	$('a.external, a.blank').attr('target','_blank');
	
	
	$('#news-head h6').flash({ 
			src: 'swf/dokyo.swf',
			wmode: 'transparent', 
			flashvars: { 
				css: [
					'* { color: #ffffff; }',
					//'a { color: '+ c +'; text-decoration: underline; }',
						//'a { text-decoration: underline; }',
					//'a:hover { text-decoration: none; }'
				].join(' ')
			}
		},{ version: 7,update:false },
		function(html) {
			html.flashvars.txt = this.innerHTML;
			this.innerHTML = '<div>'+this.innerHTML+'</div>';
			var $alt = $(this.firstChild);
			html.height = $alt.height();
			html.width = $alt.width();
			$alt.addClass('alt');
			$(this).addClass('flash-replaced').prepend($.fn.flash.transform(html));						
		}
	);
	
	
	
}); // ready


function writeFlashMedia(id,src,o){	
	$(id).empty();	
	$(id).html("<div id='swf'></div>");	
	$(id+" #swf").flash(
		{ 
		  src: 'swf/'+src,
		  width: '100%',
		  height: '100%',
		  wmode: 'transparent',
		  flashvars: o
		},
		{ version: 8,update:false }
	);	
}

function sifr(e){		
	var c = $("#header").css('background-color');
	//alert(c);
	if(!c.indexOf("rgb"))	c = rgbConvert(c);
	
//	$('h1, h2, h3, h4, h5, h6,ul.pagenav li').flash(
	//$('h1, h2, h3, h4, h5, h6').flash({ 
	var elems = (e) ? e +' h1,'+ e +' h2,'+ e +' h3,'+ e +' h4,'+ e +' h5':'h1, h2, h3, h4, h5';
	
	$(elems).flash({ 
			src: 'swf/dokyo.swf',
			wmode: 'transparent', 
			flashvars: { 
				css: [
					'* { color: '+ c +'; }',
					'a { color: '+ c +'; text-decoration: underline; }',
						//'a { text-decoration: underline; }',
					'a:hover { text-decoration: none; }'
				].join(' ')
			}
		},{ version: 7,update:false },
		function(html) {
			html.flashvars.txt = this.innerHTML;
			this.innerHTML = '<div>'+this.innerHTML+'</div>';
			var $alt = $(this.firstChild);
			html.height = $alt.height();
			html.width = $alt.width();
			$alt.addClass('alt');
			$(this).addClass('flash-replaced').prepend($.fn.flash.transform(html));						
		}
	);			
}

function rgbConvert(str) {
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   return ('#' + str.join(""));
}

