/**
 * zudolab TabContents
 *
 * @version    1
 * @copyright    (c)2008 Takeshi Takatsudo (http://zudolab.net/)
 * @license    MIT (http://www.opensource.org/licenses/mit-license.php)
 */

(function($){

	TabContents = function(selector)
	{
		this.selector = selector;
		this.elemSets = [];
		
		/* exec setup when onload */
		var self = this;
		$(function(){ self.setup(); });
	}
	
	TabContents.prototype.setup = function()
	{
		this.prepareSets();
		if(!this.elemSets) return;
		this.preploadTabImgs();
		this.enable1stSelectedSet();
		this.setEvents();
	}
	TabContents.prototype.prepareSets = function()
	{
		var self = this;
		var $elems = $(self.selector);
		if(!$elems) return;
		$elems.each(function(){ 
			var anchor = this;
			var $anchor = $(anchor);
			var $img = $(this).find("img").eq(0);
			var img = ($img.length==1) ? $img.get(0) : null;
			if(img){
				var imgSrc = $img.attr("src");
				var srcOff = imgSrc;
				var srcOn = imgSrc.replace(/\/off\//,"/active/");
			}
			var selected = $anchor.hasClass("showThis") ? true : false;
			$anchor.removeClass("showThis");
			var $content = $($anchor.attr("href"));
			self.elemSets.push({
				anchor: anchor,
				$content: $content,
				selected: selected,
				img: img,
				srcOff: srcOff ? srcOff: null,
				srcOn: srcOn ? srcOn : null
			});
		});
	}
	TabContents.prototype.setEvents = function()
	{
		var self = this;
		for(var i=0,set; set=this.elemSets[i]; i++){
			$(set.anchor).click(function(){
				self.changeTabTo(this);
				return false;
			});
		}
	}
	TabContents.prototype.changeTabTo = function(anchor)
	{
		var newSet = this.getElemSetFromAnchor(anchor);
		var lastSet = this.getLastSelectedElemSet();
		if(newSet==lastSet) return;
		this.disableSet(lastSet);
		this.enableSet(newSet);
	}
	TabContents.prototype.disableSet = function(set)
	{
		$(set.anchor).css("cursor","pointer");
		if(set.img) set.img.src = set.srcOff;
		$(set.anchor).removeClass("on");
		set.$content.hide();
		set.selected = false;
	}
	TabContents.prototype.enableSet = function(set)
	{
		$(set.anchor).css("cursor","default");
		if(set.img) set.img.src = set.srcOn;
		$(set.anchor).addClass("on");
		set.$content.show();
		set.selected = true;
	}
	TabContents.prototype.enable1stSelectedSet = function()
	{
		for(var i=0,set; set=this.elemSets[i]; i++){
			if(set.selected){
				this.enableSet(set);
				return;
			}
		}
	}
	TabContents.prototype.preploadTabImgs = function()
	{
		for(var i=0,set; set=this.elemSets[i]; i++){
			if(!set.img) continue;
			if(set.selected){
				(new Image).src = set.srcOff;
			}else{
				(new Image).src = set.srcOn;
			}
		}
	}
	TabContents.prototype.getElemSetFromAnchor = function(anchor)
	{
		for(var i=0,set; set=this.elemSets[i]; i++){
			if(set.anchor==anchor) return set;
		}
	}
	TabContents.prototype.getLastSelectedElemSet = function()
	{
		for(var i=0,set; set=this.elemSets[i]; i++){
			if(set.selected) return set;
		}
		return false
	}
})(jQuery);





/*=====================================================
meta: {
  title: "jquery-opacity-rollover.js",
  version: "2.1",
  copy: "copyright 2009 h2ham (h2ham.mail@gmail.com)",
  license: "MIT License(http://www.opensource.org/licenses/mit-license.php)",
  author: "THE HAM MEDIA - http://h2ham.seesaa.net/",
  date: "2009-07-21"
  modify: "2009-07-23"
}
=====================================================*/
(function($) {
	
	$.fn.opOver = function(op,oa,durationp,durationa){
		
		var c = {
			op:op? op:1.0,
			oa:oa? oa:0.6,
			durationp:durationp? durationp:'fast',
			durationa:durationa? durationa:'fast'
		};
		

		$(this).each(function(){
			$(this).css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				}).hover(function(){
					$(this).fadeTo(c.durationp,c.oa);
				},function(){
					$(this).fadeTo(c.durationa,c.op);
				})
		});
	},
	
	$.fn.wink = function(durationp,op,oa){

		var c = {
			durationp:durationp? durationp:'slow',
			op:op? op:1.0,
			oa:oa? oa:0.2
		};
		
		$(this).each(function(){
			$(this)	.css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				}).hover(function(){
				$(this).css({
					opacity: c.oa,
					filter: "alpha(opacity="+c.oa*100+")"
				});
				$(this).fadeTo(c.durationp,c.op);
			},function(){
				$(this).css({
					opacity: c.op,
					filter: "alpha(opacity="+c.op*100+")"
				});
			})
		});
	}
	
})(jQuery);

