var use_local = false;
var videoPath = 'http://cdn.ecrmsuite.netdna-cdn.com/cancercouncil/cacn80-2/';

var local_videos = new Array();
local_videos[1] = 'louisa_online_master_graded';
local_videos[2] = 'fuzzy_online_master_graded';
local_videos[3] = 'anne_online_master_graded';

var flv_videos = new Array();
flv_videos[1] = (use_local) ? videoPath + local_videos[1] + '.f4v' : '1287_75599_67531_flvhigh';
flv_videos[2] = (use_local) ? videoPath + local_videos[2] + '.f4v' : '1287_75596_34073_flvhigh';
flv_videos[3] = (use_local) ? videoPath + local_videos[3] + '.f4v' : '1287_75601_28400_flvhigh';

jQuery(function(){
	jQuery('#moreHome').hide();
    jQuery('.more').show();
    jQuery('#videoButtons [href="/videos"]').attr('href', '#')
    
	// show/hide navigation on the homepage
	jQuery('.more').click(function(){
		if (jQuery(this).hasClass('open')) {
			jQuery('#moreHome').hide('slow');
			jQuery(this).removeClass('open');
			jQuery(this).text('More');
		} else {
			jQuery('#moreHome').show('slow');
			jQuery(this).addClass('open');
			jQuery(this).text('Less');
		}
		this.blur();
		return false;
	});

	// remove ugly dotted frame
	jQuery('#topContent a').click(function(){
		this.blur();
	});

	// nice scrolling for faq
	jQuery('.faq a').click(function(){
		var href = jQuery(this).attr("href");
		jQuery('html,body').animate({scrollTop: jQuery(href).offset().top},'slow');
		
		return false;
	});

	// attach hover effect to links
	jQuery('#mainNavigation a, #footer a, #subnavigation a, #content a').each(function(){
		var original = jQuery(this).css("color");
		jQuery(this).hover(function(){
			jQuery(this).animate({"color" : "#FFF"}, "fast");
		},
		function() {
			jQuery(this).animate({"color" : original}, "fast");
		});
	});

	// IE6 problem with hover over png images
	jQuery('.getStarted, .donate').hover(
		function() {
			jQuery(this).css({'cursor'	: 'pointer'});
		},
		function() {

		});

	// we must use different width depending on os	
	var fancyboxWidth;
	if ($.client.os == 'Windows' && 6 == parseInt(jQuery.browser.version))
    {
		fancyboxWidth = 810;
	}
	else if ($.client.os == 'Windows')
    {
		fancyboxWidth = 827;
	}
    else
    {
		fancyboxWidth = 825;
	}

	// display fancybox
	jQuery('.fancybox').fancybox({
		'type'				:	'iframe',
		'width'				:	fancyboxWidth,
		'height'			:	500,
		'overlayColor'		:	'#EE4498',
		'overlayOpacity'	:	0.9
//		'showCloseButton'	:	false
	});

	// target blank
	jQuery('.targetblank, .menu-item-type-custom a').click(function() {
		this.blur();
		window.open(this.href);
		return false;
	});

	jQuery('#videoHost').click(function($) {playVideo(1);});
    jQuery('#videoAmbassador').click(function($) {playVideo(2);});
	jQuery('#videoSurvivor').click(function($) {playVideo(3);});
});

// play video
function playVideo(i) {

	jQuery("#video").empty();
	//jQuery("#video").css({"display" : "block"});
	jQuery("#video").show();
    
    playIE6Video( flv_videos[i] );
	
	// flareplayer doesn't work in IE6 => use flowplayer instead
	//if (true) {
	/*if (jQuery.browser.msie && 6 == parseInt(jQuery.browser.version) || use_flash)
    {
		playIE6Video(flv_videos[i]);
	}
    else
    {
		fv = jQuery("#video").flareVideo({
			//autoplay:	true
		});

		fv.load([
            {
                //flv
                src:  flv_videos[i],
                type: 'video/x-flv'
            },
            {
                //mp4
                src:  mp4_videos[i],
                type: 'video/mp4'
            },
            {
                //mov
                src:  mov_videos[i],
                type: 'video/mp4'
            },
            {
                //ogv
                src:  ogv_videos[i],
                type: 'video/ogg; codecs="theora, vorbis"'
            }
		]);
	}*/
    return false;
}

// for IE6 use flow player
function playIE6Video(videoUrl) {
	
    if(use_local) {	
		
		flowplayer("video", "/wp-content/themes/girlsnightin/swf/flowplayer-3.2.2.swf", {
            screen:	{
                bottom: 0	// make the video take all the height
            },

            // change the default controlbar to modern
            plugins: {
                controls: {
                    url: '/wp-content/themes/girlsnightin/swf/flowplayer.controls-3.2.1.swf'
                }
            },
            clip: {
                autoPlay: true,
                url: videoUrl
            },
            canvas: {
                backgroundColor:	'#000',
                backgroundGradient: 'none'
            }
        });
        
    } else {
    
        flowplayer("video", "/wp-content/themes/girlsnightin/swf/flowplayer-3.2.2.swf", {
            screen:	{
                bottom: 0	// make the video take all the height
            },

            // change the default controlbar to modern
            plugins: {
                controls: {
                    url: '/wp-content/themes/girlsnightin/swf/flowplayer.controls-3.2.1.swf'
                },
                rtmp: {
                    url: '/wp-content/themes/girlsnightin/swf/flowplayer.rtmp-3.2.1.swf',
                    netConnectionUrl: 'rtmp://cp82079.edgefcs.net/ondemand/',
        
                    // make the rtmp plugin query the stream length from the server
                    //durationFunc: 'getStreamLength'
                }
            },
            
            clip: {
                url: videoUrl,
                provider: 'rtmp',
                autoPlay: true
            },
            
            canvas: {
                backgroundColor:	'#000',
                backgroundGradient: 'none'
            }
        });
    }
	//alert(videoUrl);
	return false;
}