$(document).ready(function(){
	
	// **************************************************************************************************************************
	// GENERAL ACTIONS
	
	// external links
	$("a[rel='external']").click(function() {
		return !window.open($(this).attr("href"));
	});
	$('.hide-with-js').hide(); // use this class to hide the message "please open this link in new window"
	
	// fade in messages
	$('.successMsg').hide();
	$('.successMsg').fadeIn(1000);
	$('.errorMsg div').hide();
	$('.errorMsg div').fadeIn(1000);
	$('.warningMsg').hide();
	$('.warningMsg').fadeIn(1000);
	
	// non-clickable links
	$(".return-false").click( function() {
		return false;
	});
	
	$("#send_request").click( function() {
		$("#request_form").submit();
	});
	
	$("#send_email").click( function() {
		$("#email_form").submit();
	});
	
	$("#send_quote").click( function() {
		$("#quote_form").submit();
	});
	
	$("a.grouped_elements").fancybox();

	
	// JUMP MENU
	$("select.jump-menu").change(function(x){
		var url = $("option:selected", this).attr("title");
		if (url.length) {
			window.location.href = url;
		}
	});
	
	// Slideshow
	$.ajax({
		type: "POST",
		url: "http://www.melfast.com/ajax_action/getIndustries",

		success: function(data){

			$('#ajax-load-slides').html(data);
			$("div#controller").jFlow({
				slides: "#slides",
				width: "637px",
				height: "338px"
			});
		},
error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
                } 
	});
      	
	// clear inputs
	$("#form-search input").each(function(i){
		var inputValue = $(this).val();
		
		$(this).focus(function(){ 
			if ($(this).val()==inputValue) {
				$(this).val("");
			}
		});
		$(this).blur(function(){ 
			if ($(this).val()=="") {
				$(this).val(inputValue);
			}
		});
	});
	
	
	// Header error message
	$(".errorMsg-overlay, .errorMsg-after").hide();
	$(".errorMsg-overlay, .errorMsg-after").fadeIn(300, function(){ 
		var elem = $(this);
		setTimeout(function(){
			$(elem).fadeOut(300);
		}, 1200);
	});
	
	$(".toggle_content > a").click(function(){
		var content_block = $(this).attr("rel");
		var status = $("#"+content_block).css("display");
		$("#"+content_block).slideToggle(0);

		return false;
				
	});
	
	// Fading links
	$(".fading-link img").fadeTo(1000, 0.50);
	$(".fading-link").hover(
		function(){
			$("img", this).fadeTo(50, 1);
		},
		function(){
			$("img", this).fadeTo(50, 0.50);
		}
	);
	
	// END GENERAL ACTIONS
	// **************************************************************************************************************************
	
	// Cufon Text Replacement
	Cufon.replace('h1.replace, .replace-big-blue, .replace-white, .replace-small', {hover: true, hoverables:{a: true, h2:true} });
	Cufon.replace('.over_slide',{textShadow: '#fff 0px 0px, #000 1px 1px'});
	
});

