// this is the main startup script
$(function () {

	// replace heading fonts (all pages)
	Cufon.replace('#nav li a, #content h1, #content h2, #content h3, #content h4, #content ul.imglist h3, #footer h6, #rotator p.title', {
        fontFamily: 'Aller',
		hover: true,
		forceHitArea: true
	});

	// wire rotator (home page)
	$("#rotator").rotator({
		itemFade: 500,
		pagerFade: 0,
		itemShow: 3000,
		autoPlay : true,
		showPager : true
	});
	
	// wire superfish navigation (all pages)
	$('#nav')
		.superfish({
			delay: 300,
			speed: 100,
			animation: {height:'show'},
			dropShadows: false
		});

	// IE6 bgiframe fix - do it only if bgIframe is loaded (all pages)
	if($.fn.bgIframe)
		$('#nav').find('ul').bgIframe({opacity:false});

	// wire fancybox
	$("a.swell").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200,
		overlayShow		: 	false
	});

$("a.contact").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'speedIn'			: 200, 
				'speedOut'			: 200,
				'scrolling'			: 'auto',
				overlayShow			: false
			});

$("a.tubeit").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
						'wmode'		: 'transparent',
						'allowfullscreen'	: 'true'
							}
				});
		return false;
});


$(function(){
    $('a.jump').click(function(){
        window.open(this.href);
        return false;
    });
});

// handles the accordian tabs for the glossary
$(".dropdown_list h3:first").addClass("active");
	$(".dropdown_list p:not(:first)").hide();

	$(".dropdown_list h3").click(function(){

	  $(this).next("p").slideToggle("medium")
	  .siblings("p:visible").slideUp("medium");
	  $(this).toggleClass("active");
	  $(this).siblings("h3").removeClass("active");

	});
	
	// contact form hide success/error messages (contact page)
	$('#contactform div.success, #contactform div.error').hide();
	// define ajax submit handler
	var AjaxSubmit = function(){
		var btnText=$('#contactform .submit').val();
		// inform client that data is been sent:
		$('#contactform .submit').val('Sending...');
		$.ajax({
			type: 'POST',
			url: $('#contactform').attr('action'),
			data: $('#contactform').serialize(),
			// successful POST - display result in success div:
			success: function(msg){
				$('#contactform .form').slideUp(500,function(){
					$('#contactform div.success').fadeIn(500);
				});
			},
			// error on server, or wrong url - display status text in error div:
			error: function(response) {
				$('#contactform .submit').val(btnText);
				$('#contactform div.error').html(response.statusText).slideDown(500);
			}
		});
		// prevent default submit button behaviour:
		return false;
	}
	// wire client validation for forms:
	$('#contactform').validate({
		submitHandler: AjaxSubmit
	});
	
	$('#postform').validate();

$("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("thumb_view");
        });
    }, function () {
        $(this).removeClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("thumb_view");
        });
    }); 
});
