//globals
var wallSet = false;
var myFlashObjects = new Array(0, 0, 0, 0);
var activeImage = "#thumb1";

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;   
    });
    jQuery('.navigation_page').click (function() {
        carousel.scroll(jQuery.jcarousel.intval(this.tabIndex));
        jQuery('.boxindex').removeClass('selected');
        jQuery('#boxindex_'+carousel.first).addClass('selected');
        jQuery(this).removeClass('selected');
        jQuery(this+"_"+carousel.first).addClass('active');
    });
};
function mycarousel_itemLoadCallback(carousel) {
	// Added this function due to a safari bug where it reloads all swfs each carousel movement.
	if(carousel.first != 1) {
		unloadBcVideo();
	}
    jQuery('.boxindex').removeClass('selected');
    jQuery('#boxindex_'+carousel.first).addClass('selected');
    jQuery('.navigation_page').removeClass('selected');
    jQuery('#navigation_'+carousel.first).addClass('selected');
	loadSWFobject(carousel.first);
	// I no longer need this function do to the function unloadBcVideo()
	// pauseBcVideo();
    try { 
    callToActionscript('killWallFocus')
    }
    catch(err)
    {
    }
    s.t()
    return false;
};
function loadSWFobject(currentPage) {
	if(myFlashObjects[currentPage]) {
		return;
	} else {
			switch(currentPage) {
				case 1:
					break;
				case 2:
					var fo = new FlashObject("http://s3.amazonaws.com/content.newsok.com/newsok/images/profile/opubco/mediaWall.swf", "opubco_mediaWall", "870", "320", 9, "#333333");
					fo.addVariable("xmlFile", "http://newsok.com/xml_block/opubco_mediawall_xml");
					fo.addParam("wmode", "transparent");
                    fo.addParam("allowScriptAccess", "always");
					fo.write("mediaWall");
                    wallSet = true;
					break;
				case 3:
					var so = new FlashObject("http://s3.amazonaws.com/content.newsok.com/newsok/images/profile/opubco/mediaTimeline.swf", "opubco_timeline", "870", "320", "9.0.0", "#333333");
					so.addVariable("xmlFile", "http://newsok.com/xml_block/opubco_timeline_xml");
					so.addParam("wmode", "transparent");
					so.write("mediaTimeline");
					break;
				case 4:
					break;
				default:
					break;
			}
			myFlashObjects[currentPage] = 1;
	}
}

jQuery(document).ready(function(){
        jQuery.localScroll();
        //  nav tab animation
        var navDuration = 150; //time in miliseconds
        jQuery('#nav li a').hover(function() {
          jQuery(this).animate({ paddingTop:"50px"  }, navDuration);
        }, function() {
             jQuery(this).animate({ paddingTop:"14px"}, navDuration);
        });

    jQuery('#mycarousel').jcarousel({
        visible: 1,
        initCallback: mycarousel_initCallback,
        itemLoadCallback: {onAfterAnimation: mycarousel_itemLoadCallback},
        animation: "slow",
        scroll: 1
    });

	jQuery("#thumbs_quotes .thumbs_container img").hover(function() {
		jQuery (activeImage).fadeTo('fast', .25);
		jQuery (this).fadeTo('fast', 1);
		activeImage = this;
		loadQuote(this.id);
	});

});

function loadQuote(el) {
	switch(el) {
		case "thumb1":
			document.getElementById("quoteblock").innerHTML = quote1;
			document.getElementById("author").innerHTML = "~" + author1;
			break;
		case "thumb2":
			document.getElementById("quoteblock").innerHTML = quote2;
			document.getElementById("author").innerHTML = "~" + author2;
			break;
		case "thumb3":
			document.getElementById("quoteblock").innerHTML = quote3;
			document.getElementById("author").innerHTML = "~" + author3;
			break;
		case "thumb4":
			document.getElementById("quoteblock").innerHTML = quote4;
			document.getElementById("author").innerHTML = "~" + author4;
			break;
		case "thumb5":
			document.getElementById("quoteblock").innerHTML = quote5;
			document.getElementById("author").innerHTML = "~" + author5;
			break;
		case "thumb6":
			document.getElementById("quoteblock").innerHTML = quote6;
			document.getElementById("author").innerHTML = "~" + author6;
			break;
	}
}
function playBcVideo() {
    document.getElementById('introVideo').style.display = 'none';
    document.getElementById('media_intro').style.display = '';
}
function unloadBcVideo() {
    document.getElementById('media_intro').style.display = 'none';
    document.getElementById('introVideo').style.display = '';
}
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(str) 
{
     getFlashMovie("opubco_mediaWall").sendToActionscript(str);
}
