/************************************************
  
    Site Name: 
	Description: common script
	Version: 
	Author: 
	Last Modified :

************************************************/



// ROLLOVER ======================================================================================

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_def."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_def.", "_ovr."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_ovr.", "_def."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}



// SMOOTH SCROLL ===========================================================================


$(function() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 30;
				var scldurat = 1200;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
});



// TOGGLE CONTENTS ===========================================================================

$(document).ready(function(){
	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 
	//Switch the "Open" and "Close" state per click
	$("h2.trigger").toggle(
		function(){
			$(this).addClass("active");
		},
		function () {
			$(this).removeClass("active");
		}
	);
	//Slide up and down on click
	$("h2.trigger").click(
		function(){
			$(this).next(".toggle_container").slideToggle("slow",
				function(){
					var src=$(this).prev(".trigger").children().children().attr("src");
					var flag=src.indexOf("_crt");
					if(flag == -1){
						src_new=src.substr(0, src.lastIndexOf('_'))+ '_crt.gif';
					}else{
						src_new=src.substr(0, src.lastIndexOf('_'))+ '_def.gif';
					}
					$(this).prev(".trigger").children().children().attr('src', src_new);
				}
			);
		}
	);
});


