$(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));						
		}
	);
	
	
	$('#tsr_news  ul li:not(:first)').hide();
	$('#tsr_news  ul').slideshow({
		slide_element: 'li',
		timeout:3000,
		//pan:true,
		onOver : function() {	
			this.stop();			
		},
		onOut : function() {	
			this.play();			
		}	
	});
	/*
	$('#tsr_sejournez ul a').hover(		
		function(){
				tsr_tmp_img = $('#tsr_sejournez > img').attr('src');
				var tmp = $(this).attr('href').split('.');
				var i = 'img/tsr-img-'+ tmp[0] +'.gif';
				$('#tsr_sejournez > img').attr('src',i);				
		},
		function(){
			$('#tsr_sejournez > img').attr('src',tsr_tmp_img);
		}
	);
	*/
	$('a.tsr-img-pan').hover(		
		function(){
			var el = $(this).find('img');
			var ih = el.height();
			var gih =$(this).height();			
			var dif = ih - gih;
					
			if(ih > gih){						
				if(dif != 0){
					el.animate({'top': '-'+dif+'px'}, 500);
				}
			}	
		},
		function(){
			$(this).find('img').animate({'top': '0px'}, 500);
		}
	);
	
	$('.tsr-img-swap ul a').hover(		
		function(){
				
				var tsr_tmp_parent = $(this).parent().parent().parent()
				
				//debug(tsr_tmp_parent);
				
				tsr_tmp_img = tsr_tmp_parent.find('img');
				tsr_tmp_img_src = tsr_tmp_img.attr('src');
				var tmp = $(this).attr('href').split('.');
				var i = 'img/tsr-img-'+ tmp[0] +'.gif';
				tsr_tmp_img.attr('src',i);				
		},
		function(){
			tsr_tmp_img.attr('src',tsr_tmp_img_src);
		}
	);
	
	
}); // ready
function log($s) {
	if (window.console && window.console.log)
	 window.console.log($s);
};


function debug($obj) {
	if (window.console && window.console.debug)
	 window.console.debug('debug: %o', $obj);
};

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(""));
}

