//@cc_on document.execCommand("BackgroundImageCache", false, true);

$(document).ready(function(){
	// allowScriptAccess must be set to allow the Javascript from one domain to access the swf on the youtube domain
	var params = {
		allowScriptAccess: "always", bgcolor: "#cccccc"
	};
	// This sets the id of the object or embed tag to 'myytplayer'.
	// You then use this id to access the swf and make calls to the player's API
	
	if (document.getElementById('ytapiplayer'))
	{
		var atts = {
			id: "myytplayer"
		};
		swfobject.embedSWF(
			"http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", 
			"ytapiplayer", "475", "228", "8", null, null, params, atts
		);
	}
	
	if (document.getElementById('slider'))
		$("#slider").slider();
	//var feed_url = 'http://gdata.youtube.com/feeds/api/users/RaeIndigoCom/uploads';
	
	if (document.getElementById('mycarousel'))
	{
		jQuery(document).ready(function() {
			jQuery('#mycarousel').jcarousel({
				size: mycarousel_itemList.length,
				itemLoadCallback: { onBeforeAnimation: mycarousel_itemLoadCallback }
			});
		});
	}

	$('a.external').click(windowOpen);
	$('area.external').click(windowOpen);

});

function windowOpen() 
{
	window.open($(this).attr('href'), $(this).attr('title'));
	return false;
}

function onYouTubePlayerReadyRaeIndigo(){
	// Play intro video
	loadNewVideo('ajZNY6XzmH4', 0);
	
	// Setup controls
	$('#videoPausePlay').click(function(){
		switch($('#videoPausePlay').attr('src')){
			case 'img/video_button_pause.png':
				pause();
				break;
			case 'img/video_button_play.png':
				play();
				break;
		}
	});
	
	$('#slider').bind('slidechange', function(event, ui){
		if(event.originalEvent){
			seekTo($('#slider').slider('value')/100 * getDuration());		
		}
	});
}

function mycarousel_itemLoadCallback(carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }
        if (i > mycarousel_itemList.length) {
            break;
        }
        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item){
	return '<img src="' + item.url + '" width="56" height="41" alt="' + item.title + '" onclick="javascript:loadNewVideo(\'' + item.videoId + '\', 0)" />';
};
