var playersrc = '';

$(document).ready(function(){

	$('#google_translate').hide();
	$('#translate_button').click( function() {
		$(this).hide();
		$("#google_translate").slideToggle(500);
	});

	$('#tabs div.tab_pane').hide();
	$('#tabs div.tab_pane:first').show();
	$('#tabs ul.tab_nav li:first').addClass('here');
	$('#tabs ul.tab_nav li a').click(function(){
		$('#tabs ul.tab_nav li').removeClass('here');
		$(this).parent().addClass('here');
		var currentTab = $(this).attr('href');
		$('#tabs div.tab_pane').hide();
		$(currentTab).show();
		return false;
	});

	$('#cycle').cycle({ 
		fx: 'scrollHorz',
		speed: 1000,
		timeout: 0,
		activePagerClass: 'selected',
		prev: '#cycle_prev',
		next: '#cycle_next',
		pager: '#cycle_thumbs',
		after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			$('#cycle_caption').html('<p>' + this.title + '</p>');
			var ifr = $(currSlideElement).find('iframe');
			if (ifr.length > 0)
			{
				playersrc = ifr.attr('src');
				ifr.attr('src','http://google.com');
			}	
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			var ifr = $(nextSlideElement).find('iframe');
			if (ifr.length > 0)
			{
				if (playersrc != '')
					ifr.attr('src',playersrc);
			}	
		},
		pagerAnchorBuilder: function(idx, slide) { 
			return '#cycle_thumbs li:eq(' + idx + ') a'; 
		}
	});
	$('#cycle_caption').html('<p>' + $('#cycle li').attr("title") + '</p>'); // build first caption
	if ( $("#cycle li").length <= 1 ) {$(".gallery_thumbs").hide();}; // hides pager if only 1

	$('#cycle_fg').cycle({ 
		cleartypeNoBg: true,
		fx: 'scrollHorz',
		speed: 500,
		timeout: 6000,
		pause: 1,
		activePagerClass: 'selected',
		prev: '#cycle_prev,#cycle_other_prev',
		next: '#cycle_next,#cycle_other_next',
		pager: '#cycle_thumbs',
		after: function ( currSlideElement, nextSlideElement, options, forwardFlag ) {
			$('#cycle_fg_caption').html('<p>' + this.title + '</p>');
		},
		before: function ( currSlideElement, nextSlideElement, options, forwardFlag ) {
			$('#cycle_bg').cycle( options.nextSlide );
		},
		pagerAnchorBuilder: function(idx, slide) { 
			return '#cycle_thumbs li:eq(' + idx + ') a'; 
		}
	});
	$('#cycle_fg_caption').html('<p>' + $('#cycle_fg li').attr("title") + '</p>'); // build first caption

	$('#cycle_bg').cycle({ 
		fx: 'scrollUp',
		speed: 1250,
		fit: 1,
		timeout: 0,
		slideResize:0,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){ 
			$(nextSlideElement).width( $(window).width() ); 
			$(nextSlideElement).height( ($(window).width()/2) ); 
		}
	});

	$(window).resize(function() {
		$('#cycle_bg > div').each( function () {
			$(this).width( $(window).width() );
			$(this).height( 600 );
		});
	});
	
	// open facebook in new window
	$('#nav_full_facebook a').attr('target','_blank');

});

