var moviename = "index";

function thisMovie(moviename) {
    // IE and Netscape refer to the movie object differently - this function returns the appropriate syntax depending on the browser.
    if (navigator.appName.indexOf ("Microsoft") !=-1) {
        return window[moviename]
        }
    else {
        return document[moviename]
        }
    }
function spin() {
    thisMovie(moviename).TGotoFrame("_root","30");
    setFlashVariables('index','res2=20%');
    }
 function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
    }
function init() {
    thisMovie(moviename).TGotoFrame("_root","10");
    getFlashMovie("index").sendVarsToFlash($('xxx1').value, $('xxx2').value, $('xxx3').value);
    getFlashMovie("index").sendMovieTitles($('yyy1').value, $('yyy2').value, $('yyy3').value);
    getFlashMovie("index").sendMovieLinks($('link1').value, $('link2').value, $('link3').value);
    getFlashMovie("index").sendIsAdvertisement($('isAdvertise1').value, $('isAdvertise2').value, $('isAdvertise3').value);
///    getFlashMovie("index").sendAdvertiseID($('advertiseId1').value, $('advertiseId2').value, $('advertiseId3').value);
///    getFlashMovie("index").sendVarsToFlash($('xxx1').value, $('xxx2').value, $('xxx3').value);
///    getFlashMovie("index").sendMovieTitles($('yyy1').value, $('yyy2').value, $('yyy3').value);

    setTimeout('show_buttons(1)', 2100);
    setTimeout('show_buttons(2)', 2100);
    setTimeout('show_buttons(3)', 2100);
    }
function show_buttons(item){
	$('advertisementText'+item).innerHTML = '';
    if ( $('isAdvertise'+item).value==0 ) {

	    $('button'+item+'turkey').src = 'images/quickfire/up_turkey.gif';
	    $('button'+item+'turkey').style.cursor = 'pointer';
///	    $('button'+item+'turkey').onmousedown = function(){};
	    $('button'+item+'turkey').onmouseup = function(){this.src='images/quickfire/up_turkey.gif'};
	    $('button'+item+'turkey').onmousedown = function(){
		this.src='images/quickfire/down_turkey.gif'
	        hide_buttons(item);
	        new Ajax.Updater({success:'wr'+item}, "ajax.php?main_page=quickfirevote&item="+item+"&id="+$('zzz'+item).value+'&vote=1', {
	        onSuccess: function() {
	            setTimeout('makeSound("1")', 200);
	            setTimeout('sendVote("'+item+'", $("ttt'+item+'").value)', 500);
	            setTimeout('notseenwrapper("'+item+'")', 3500);
	            },
	        on404:function() {
	            alert('An error occured while processing your request. Please try again.\nIf this message re-appears, please notify the owner of the website.');
	            },
	        asynchronous: false,
	        evalScripts:true
	        });
	        };

	    $('button'+item+'notturkey').src = 'images/quickfire/up_not.gif';
	    $('button'+item+'notturkey').style.cursor = 'pointer';
///	    $('button'+item+'notturkey').onmousedown = function(){};
	    $('button'+item+'notturkey').onmouseup = function(){this.src='images/quickfire/up_not.gif'};
	    $('button'+item+'notturkey').onmousedown = function(){
		this.src='images/quickfire/down_not.gif'
	        hide_buttons(item);
	        new Ajax.Updater({success:'wr'+item}, "ajax.php?main_page=quickfirevote&item="+item+"&id="+$('zzz'+item).value+'&vote=0', {
	        onSuccess: function() {
	            setTimeout('makeSound("2")', 200);
	            setTimeout('sendVote("'+item+'", $("ttt'+item+'").value)', 500);
	            setTimeout('notseenwrapper("'+item+'")', 3500);
	            },
	        on404:function() {
	            alert('An error occured while processing your request. Please try again.\nIf this message re-appears, please notify the owner of the website.');
	            },
	        asynchronous: false,
	        evalScripts:true
	        });
	        };
    }
    else {
	hide_buttons_advertisement (item);
	if ($('advIsPremium'+item).value == "1") {
		var adDisplay = true;
		for (cou = 1; cou<=3; cou++) {
			if ($('advertiseId'+cou).value == $('advertiseId'+item).value && cou!=item)
				adDisplay = false;
		}

		if (adDisplay) {
			$('advertisementText'+item).innerHTML = "<img src=" + $('advPremiumText'+item).value + " />";
		}
	}
	if ( ifClaimPrize () ) {
		getFlashMovie("index").sendClaim ($('linkClaim1').value);
		hide_buttons ();
	}
    }

    $('button'+item+'notseen').src = 'images/quickfire/up_notseen.gif';
    $('button'+item+'notseen').style.cursor = 'pointer';
///    $('button'+item+'notseen').onmousedown = function(){};
    $('button'+item+'notseen').onmouseup = function(){this.src='images/quickfire/up_notseen.gif'};
    $('button'+item+'notseen').onmousedown  = function(){
	this.src='images/quickfire/down_notseen.gif'
        hide_buttons(item);
        new Ajax.Updater({success:'wr'+item}, "ajax.php?main_page=quickfirevote&item="+item+"&id="+$('zzz'+item).value+'&vote=2', {
        onSuccess: function() {
            setTimeout('notseenwrapper("'+item+'")', 800);
            setTimeout('makeSound("3")', 800);
            },
        on404:function() {
            alert('An error occured while processing your request. Please try again.\nIf this message re-appears, please notify the owner of the website.');
            },
        asynchronous: false,
        evalScripts:true
        });
        };
    }
function makeSound(what){
    var so = new SWFObject("flashPlayer.swf", "turkey-sounds", "12", "11", "7", "#FFFFFF");
    so.addVariable("autoPlay", "yes");
    so.addParam("wmode", "transparent");
    if(what==1)
        so.addVariable("soundPath", 'sounds/squirt.mp3');
    else if(what==2)
        so.addVariable("soundPath", 'sounds/pop.mp3');
    else if(what==3)
        so.addVariable("soundPath", 'sounds/whoosh.mp3');
    so.write("flashPlayer");
    }
function hide_buttons(item){
    $('button'+item+'turkey').src = 'images/quickfire/grey_turkey.gif';
    $('button'+item+'turkey').style.cursor = '';
    $('button'+item+'turkey').onmouseup = function(){};
    $('button'+item+'turkey').onmousedown = function(){};
    $('button'+item+'turkey').onmouseclick = function(){};

    $('button'+item+'notturkey').src = 'images/quickfire/grey_not.gif';
    $('button'+item+'notturkey').style.cursor = '';
    $('button'+item+'notturkey').onmouseup = function(){};
    $('button'+item+'notturkey').onmousedown = function(){};
    $('button'+item+'notturkey').onmouseclick = function(){};

    $('button'+item+'notseen').src = 'images/quickfire/grey_notseen.gif';
    $('button'+item+'notseen').style.cursor = '';
    $('button'+item+'notseen').onmouseup = function(){};
    $('button'+item+'notseen').onmousedown = function(){};
    $('button'+item+'notseen').onmouseclick = function(){};
    }
function updateItem(item) {
    new Ajax.Updater({success:'wr'+item}, "ajax.php?main_page=quickfire&item="+item, {
        onSuccess: function() {
            },
        on404:function() {
            alert('An error occured while processing your request. Please try again.\nIf this message re-appears, please notify the owner of the website.');
            },
        asynchronous:false,
        evalScripts:true
        });
    }
function notseenwrapper(item) {
    new Ajax.Updater({success:'wr'+item}, "ajax.php?main_page=quickfire&item="+item, {
        onSuccess: function() {
            setTimeout('notseen("'+item+'")', 500);
            },
        on404:function() {
            alert('An error occured while processing your request. Please try again.\nIf this message re-appears, please notify the owner of the website.');
            },
        asynchronous: false,
        evalScripts:true
        });
    }
function notseen(item) {
///		alert(item);
//    getFlashMovie("index").sendVarsToFlash($('xxx1').value, $('xxx2').value, $('xxx3').value);
	getFlashMovie("index").sendMovieTitle(item,$('yyy'+item).value);
	getFlashMovie("index").sendVarsToFlash2(item , $('xxx'+item).value);
	getFlashMovie("index").sendMovieLink(item, $('link'+item).value);
	getFlashMovie("index").sendIsAdvertisement2(item, $('isAdvertise'+item).value);
///sendTitle(item, singleTitle);
///    getFlashMovie("index").sendMovieLinks($('link1').value, $('link2').value, $('link3').value);

///    getFlashMovie("index").sendIsAdvertisement($('isAdvertise1').value, $('isAdvertise2').value, $('isAdvertise3').value);
                                    
		

    getFlashMovie("index").reSlide(item);
    setTimeout('show_buttons('+item+')', 1800);
    /*BV:
    if(item==1)
        getFlashMovie("index").reSlide1();
    else if(item==2)
        getFlashMovie("index").reSlide2();
    else if(item==3)
        getFlashMovie("index").reSlide3();
    end BV.*/
    }
function sendVote(item,voteValue) {
    thisMovie(moviename).TGotoFrame("_root.spin"+item,"50");
    getFlashMovie("index").vote(item,voteValue);
    }

function hide_buttons_advertisement (item){
    $('button'+item+'turkey').src = 'images/quickfire/grey_turkey.gif';
    $('button'+item+'turkey').style.cursor = '';
    $('button'+item+'turkey').onmouseup = function(){};
    $('button'+item+'turkey').onmousedown = function(){};
    $('button'+item+'turkey').onmouseclick = function(){};

    $('button'+item+'notturkey').src = 'images/quickfire/grey_not.gif';
    $('button'+item+'notturkey').style.cursor = '';
    $('button'+item+'notturkey').onmouseup = function(){};
    $('button'+item+'notturkey').onmousedown = function(){};
    $('button'+item+'notturkey').onmouseclick = function(){};
    }

function ifClaimPrize ()
{
	if ( $('isAdvertise1').value=='1' && $('isAdvertise2').value=='1' && $('isAdvertise3').value=='1' )
	if ( $('advIsPremium1').value=='1' && $('advIsPremium2').value=='1' && $('advIsPremium3').value=='1' )
	if ( $('advertiseId1').value==$('advertiseId2').value && $('advertiseId2').value==$('advertiseId3').value )
		return true;

	return false;
}
