$(document).ready(function(){

	$("a[rel=external]").attr("target", "blank");
	
	if ($(".welcome").length) {
		$('.welcome').truncate({max_length: 665});
	}
	
	$("a.toplink").click(function(){ 
		$.scrollTo('#wrapper', 300);
	});
	
	$("a[rel=modal]").fancybox({
		'callbackOnStart': 
			function() {
				$('#slideshow').cycle('pause');
			},
		'callbackOnClose': 
			function() {
				$('#slideshow').cycle('resume');
			},
		'zoomSpeedIn':	300, 
		'zoomSpeedOut': 300, 
		'overlayShow':	true,
		'imageScale': true,
		'overlayOpacity': .9,
		'centerOnScroll': true,
		'zoomOpacity': true,
		'padding': 1
	});
	
	$("a.gallery").fancybox({
		'callbackOnStart': 
			function() {
				$('#slideshow').cycle('pause');
			},
		'callbackOnClose': 
			function() {
				$('#slideshow').cycle('resume');
			},
		'zoomSpeedIn':	300, 
		'zoomSpeedOut': 300, 
		'overlayShow':	true,
		'imageScale': true,
		'overlayOpacity': .9,
		'centerOnScroll': true,
		'zoomOpacity': true,
		'padding': 1
	});

	$("a[rel=video_viewer]").fancybox({
		'callbackOnShow': function() { 
  			$("#fancy_right").hide(); 
  			$("#fancy_left").hide(); 
  		}, 
		'zoomSpeedIn':	300, 
		'zoomSpeedOut': 300, 
		'overlayShow':	true,
		'imageScale': true,
		'overlayOpacity': .9,
		'centerOnScroll': true,
		'zoomOpacity': true,
		'hideOnContentClick': false,
		'padding': 1
	});

	$("#press_thumbnails .thumb a").hoverIntent({
		sensitivity: 3, 
		interval: 100, 
		over: imageRollOver,
		out: imageRollOut,
		timeout: 500
	});
	
	$("#slideshow").cycle({ 
		fx: 'fade',
		speed: 3000,
		timeout: 2000,
	    cleartype: true,
    	cleartypeNoBg: true
	});
	
	$('.quotes_slideshow').cycle({ 
    	fx:    'fade', 
    	speed: 3000,
		timeout: 2000,
    	cleartype: true,
    	cleartypeNoBg: true
	});
	
	if ($("#faq").length) {
		$('#faq').accordion({
			active: 'li.active',
			alwaysOpen: false,
			header: "li .faq_header",
			clearStyle: true,
			autoHeight: false
		});
	}
	
	if ($(".accordion").length) {
		$('.accordion').accordion({
			active: 'li.active',
			alwaysOpen: false,
			header: "span.header",
			clearStyle: true,
			autoHeight: false,
			navigation: true
		});
	}
	
	if($.browser.msie) {
		return(true);
	} else {
		if ($(".accordion .header").length) {
			$(".accordion .header").corners("5px transparent");
			$(".price").corners("5px transparent");
		}
	}

});

function imageRollOver() {
	
	var imageSource = $(this).children('img').attr("title");
	var fullSize = $(this).attr("href");
	var imageTitle = $(this).children().find('.title').text();
	var imageInfo = $(this).parent().children('.img_description').html();
	var currentImage = $('#press_fullsize a img').attr("src");
	
	$(this).children('img').animate({
		opacity: 1.0
	},200);

	if (imageSource != currentImage) {
		$('#press_fullsize').block({ 
			message: '<div class="loader"></div>',
			baseZ: 5000,
			fadeIn:  100,
			fadeOut:  100,
			timeout: 1000,
			css: { 
				border: 'none', 
				padding: '5px', 
				backgroundColor: '#fff',
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: '.8', 
				color: '#fff'
			}
		});
		
		$("#press_fullsize a img").animate({ 
			opacity: "hide"
		}, function() {
			$("#press_fullsize a img").load(function()
			{
				$(this).hide();
				$('#press_fullsize').unblock();
				$('#image_info').html(imageInfo);
				$('#press_fullsize a').attr({href: fullSize});
				$('#press_fullsize a img').animate({
					opacity: "show"
				});
			});
			$('#press_fullsize a img').attr({src: imageSource, alt: imageTitle});
		});
	}
	
	return false;
}

function imageRollOut() {
	$(this).children('img').animate({
		opacity: 0.5
	},200);
}