$(function() {


	/* $('#hero').fadeIn(2000); */
	
	$('.slideshow').cycle();
	$('#features').cycle();

	// allows validating 
	$('.new_window').attr('target', '_blank');
	
	$('a.product_detail').click(function() {
	
		$('#transparent').show(); 
		
		$('#selected_product').hide(); 
		
		$('#selected_product').load('product.php', { product_id: $(this).attr('product_id') }, function() { 
			$('html, body').animate({scrollTop: 0}, 'slow'); 
			$('#selected_product').fadeIn('slow');  
		}); 
		
		return false; // Stops link from working where JS is active	
	});

	$('#selected_product').click(function() {
	
		$('#selected_product').html('');
		$('#selected_product').hide();
		$('#transparent').hide();
	
	});
	
	$('#copy a[title]').qtip({ position: { corner: { target: 'topRight', tooltip: 'bottomLeft' } }, style: { name: 'cream', tip: true } });
	
	$(".iframe").fancybox({
		'width'				: 650,
		'height'			: 920,
        'autoScale'     	: false,
        'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'type'				: 'iframe'
	});

    // Initialize Galleria
	$('#galleria').galleria({
	    lightbox: true
	});


	// match the height of the 2 lists in the training courses	
	var lul = $("#tc_content").children("ul").height();
	var rul = $("#tc_content div").children("ul").height();
	
	if(lul > 0 && rul > 0) {
		if(lul > rul) {
			$("#tc_content").children("ul").height(lul + 20);
			$("#tc_content div").children("ul").height(lul);
		} else {
			$("#tc_content").children("ul").height(rul);
			$("#tc_content div").children("ul").height(rul);	
		}
	}
	
	//  vertically center the title by setting line-height
	if ($("#tc_title h1").text().length > 48) {
		$("#tc_title h1").css('line-height', '20px');
	};
	
	if ($("#tc_outline").text().length > 0) {
			$("#tc_title").css('padding-top', '0');
			$("#tc_title").css('height', '60px');
			
	}
	


	$('a.lightbox').fancybox({
	
		'type' : 'image',
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'titleShow'	: 	false
	
	});

/*
	$('a.product_request_quote').click(function() {
	
		$('#transparent').show(); 
		
		$('#selected_product').hide(); 
		
		$('#selected_product').load('product_quote.php', { product_id: $(this).attr('product_id'), ajax: true }, function() { 
			$('html, body').animate({scrollTop: 0}, 'slow'); 
			$('#selected_product').fadeIn('slow');  
		}); 
		
		return false; // Stops link from working where JS is active	
	});
*/	

});

function resizeFancyBox() {
        var iFrameContentHeight = document.getElementById('fancybox-frame').contentWindow.document.body.scrollHeight;
        var iFrameContentWidth = document.getElementById('fancybox-frame').contentWindow.document.body.scrollWidth; // id of iframe

        var outer = $('#fancybox-wrap');
        var inner = $('#fancybox-inner');
        var paddingTotal = 60;
        var extra = 20; // some extra space to avoid Scrollbars

        if(iFrameContentHeight > 0 && iFrameContentWidth > 0){
                outer.css({
                        height: iFrameContentHeight + paddingTotal + extra,
                        width: iFrameContentWidth + paddingTotal + extra
                });
                inner.css({
                        height: iFrameContentHeight + extra,
                        width: iFrameContentWidth + extra
                });
                $.fancybox.center();
        }

} 
