﻿//Fade Function
(function(jQuery) {
	jQuery.fn.customFadeIn = function(speed, callback) {
		jQuery(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	jQuery.fn.customFadeOut = function(speed, callback) {
		jQuery(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

function PrintElem(elem){
    Popup(jQuery(elem).html());
}
function Popup(data){
	var mywindow = window.open('', 'Print Friendly', 'height=600,width=600');
	mywindow.document.write('<html><head><title>Print Friendly Version</title>');
	mywindow.document.write('<link href="/assets/css/print_modal.css" rel="stylesheet" type="text/css" />');
	mywindow.document.write('</head><body >');
	mywindow.document.write(data);
	mywindow.document.write('</body></html>');
	mywindow.document.close();
	mywindow.print();
	return true;
}

jQuery(document).ready(function(){	
	//Modal Window
	jQuery('a[name=modal]').click(function(e) {
		var id = jQuery(this).attr('href');
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
		jQuery('#popup_bg').css({'width':maskWidth,'height':maskHeight});	
		jQuery('#popup_bg').customFadeIn(1000, function() {});
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
		jQuery(id).css("top", jQuery(window).scrollTop() + "px");
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
		jQuery(id).customFadeIn(2000, function() {});
		jQuery('#popup_bg').fadeTo("slow",0.7);
		return false;
	});
	jQuery('a.close_popup').click(function(e) {										   
		jQuery('#popup_bg, .more_window, .download_window').customFadeOut('fast', function() {});
		return false;
	});	
	jQuery(document).keypress(function(e){
		if(e.keyCode==27){
			jQuery('#popup_bg, .more_window, .download_window').customFadeOut('fast', function() {});
		}
	});
	
	//Smooth Scroll
	jQuery('a[rel="scroll"], #side_menu a').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			var jQuerytarget = jQuery(this.hash);
			jQuerytarget = jQuerytarget.length && jQuerytarget
			|| jQuery('[name=' + this.hash.slice(1) +']');
			if (jQuerytarget.length) {
				var targetOffset = jQuerytarget.offset().top;
				jQuery('html,body')
				.animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
	
	//Back To Top
   	jQuery(window).scroll( function() { 
	    if (jQuery(window).scrollTop() > 100) {
			jQuery('#back_to_top').customFadeIn();
	    } else {
	  		jQuery('#back_to_top').customFadeOut();
	    }
	});
	
	//External Link
	jQuery('a[rel="external"]').click(function(){
        window.open( jQuery(this).attr('href') );
        return false;
    });
	
	//Print Info
	jQuery('.print_info a').click(function(){
		PrintElem(jQuery(this).attr('href'));
        return false;
    });
	
	//Set Side Menu Height
	var side_menu_height = jQuery("#side_menu").height() + 58;
	jQuery("div#side_menu_wrap").height(side_menu_height);
	
	//More Info Tooltips
	jQuery("div.expander_plus a").hover(function() {
		jQuery(this).next("span").animate({opacity: "show", top: "-40"}, "slow");
	}, function() {
		jQuery(this).next("span").animate({opacity: "hide", top: "-30"}, "fast");
	});
	
	//Symbol Tooltips
	jQuery("ul.product_symbols a").hover(function() {
		jQuery(this).next("span").animate({opacity: "show", top: "-40"}, "slow");
	}, function() {
		jQuery(this).next("span").animate({opacity: "hide", top: "-30"}, "fast");
	});
	jQuery('ul.product_symbols a').click(function(e) {
		e.preventDefault();
	});

	
	//Input Focus
	jQuery('.input_focus').each(function() {	
		jQuery(this).focus(function() {
			jQuery(this).addClass("focus_field");
		});
		jQuery(this).blur(function() {
			jQuery(this).removeClass("focus_field");
		});
	});
	
	//Contact Map	
	jQuery('a.load_map').click(function() { 
        loadMap();
        return false; 
    });
});
