/*-----------------------------------------------------------
[ jQuery Method / ver.1.2.6]
- RoolOver
- ScrollTo
- PopupWindow
- ModalWindow
- TabSelect
Version: 0.02
-----------------------------------------------------------*/

// RollOver (<img class="rollover"> img/filename_over)
$(function() {
  $("img.rollover")
    .each(function() {
      var baseImage = $(this).attr("src");
      var ext = baseImage.substring(baseImage.lastIndexOf('.'), baseImage.length);
      var overImage = baseImage.replace(ext, '_over' + ext);
      new Image().src = overImage;
      $(this).attr({basesrc: baseImage, oversrc: overImage});
    })
    .hover(function() {
        $(this).attr({src: $(this).attr("oversrc")});
      },
      function() {
        $(this).attr({src: $(this).attr("basesrc")});
    }
  );
});

//ScrollTo (<a href="#id"></a>)
jQuery.easing.quart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function(){
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
	      .animate({scrollTop: targetOffset}, 500, 'quart');
//	      .animate({scrollTop: targetOffset}, 1000);
	   return false;
	  }
	}
  });
});

//PopupWindow 
// <a href="TARGETURL" class="popupwindow" rel="PROFILENAME or profile">
// ex1: rel="height:550,width:750,toolbar:1,scrollbars:1,status:1,resizable:0,left:50,top:100"
// ex2: rel="window800"
jQuery.fn.popupwindow = function(p)
{
	var profiles = p || {};
	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		
		// for overrideing the default settings
		mysettings = (jQuery(this).attr("rel") || "").split(",");
		settings = { height:600,width:600,toolbar:0,scrollbars:0,status:0,resizable:1,left:0,top:0,center:0,createnew:1,location:0,menubar:0
		};
		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}

		// center the window
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
			window.open(this.href, name, parameters).focus();
			return false;
		});
	});

};
var profiles =
{ 
	window700:{ height:550, width:700, scrollbars:1,status:1,resizable:1 },
	window200:{height:200,width:200,status:1,resizable:0 },
	windowCenter:{ height:300, width:400, center:1 },
	windowNotNew:{ height:300, width:400, center:1, createnew:0 }
};
$(function()
{
	$(".popupwindow").popupwindow(profiles);
});


//ModalWindow
/*
$("#dialog").dialog({
    modal: true,
    overlay: {
        opacity: 0.5,
        background: "black"
    }
});
*/

//Tabify
/*
<script type="text/javascript">
$(function() {
    $('#jqtab-example1 > ul').tabs();
 });
</script>
<div id="jqtab-example1">
<ul>
<li><a href="#tab-1"><span>tab-1</span></a></li>
</ul>
<div id="tab-1"></div>
*/

(function($){$.fn.extend({tabify:function(){return this.each(function(){$(this).find("li").each(function(){if($(this).hasClass("active")){$("#"+$(this).attr("rel")).show();}else{$("#"+$(this).attr("rel")).hide();}
$(this).click(function(){$(this).parent().find("li").each(function(){$(this).removeClass("active");$("#"+$(this).attr("rel")).hide();});$("#"+$(this).attr("rel")).show();$(this).addClass("active");});});});}});})(jQuery);