/* BITOGRAFELLAS: SUPER EGO V1.0 14 MAY 2010 BY BITOGRAPHY.COM AND NEVEREVERRECORDS.COM */

$(document).ready(function() {

/* LOAD */

/* old way of displaying help immediately upon load
var apiloadbox = $('#loadbox').overlay({top: 11,expose: {color: '#fff',loadSpeed: 44,opacity: 0.56},closeOnClick: true,api: true}).load();
*/

/* INIT */

var face = new Array(0,0,0,0,0,0);
var facename = new Array('HUMAN','DESIGNER','NINJA','BEAST','ROCK','SHAMAN','HERO','STAR WARS','MIRROR','SAMURAI GHOST','GOD','SCARAB');
var completed = new Array(null,null,null,null,null,null,null,null,null,null,null,null);
var faceid = null;
var facepos = 0;
var tscore = 0;
var gocolor = 12;
var didit = false;
var justwon = true;

var apia1 = $("#a1").scrollable({size:1,clickable:false,speed:180}).circular({api:true});
var apia2 = $("#a2").scrollable({size:1,clickable:false,speed:180}).circular({api:true});
var apia3 = $("#a3").scrollable({size:1,clickable:false,speed:180}).circular({api:true});
var apib1 = $("#b1").scrollable({size:1,clickable:false,speed:180}).circular({api:true});
var apib2 = $("#b2").scrollable({size:1,clickable:false,speed:180}).circular({api:true});
var apib3 = $("#b3").scrollable({size:1,clickable:false,speed:180}).circular({api:true});

var apiloadbox = $('#loadbox').overlay({top: 11,expose: {color: '#fff',loadSpeed: 44,opacity: 0.56},closeOnClick: true,api: true});

/* FACE-NAV */

function initclick() {

if(navigator.appVersion.indexOf("iPhone") == -1 && navigator.appVersion.indexOf("iPod") == -1) {

/* CLICK */
$('#loadboxwhat').live('click',function(){
	apiloadbox.load();
});



$('#a1').live('click',function(){
	apia1.next();
	face[0] = apia1.getIndex()+1;
	if (face[0] > 11) {
		if (face[0] == 12) { face[0] = 0; } else { face[0] = 1; };
	};
	faceid = face[0];
	wintest();
});
$('#a2').live('click',function(){
	apia2.next();
	face[1] = apia2.getIndex()+1;
	if (face[1] > 11) {
		if (face[1] == 12) { face[1] = 0; } else { face[1] = 1; };
	}
	faceid = face[1];
	wintest();
});
$('#a3').live('click',function(){
	apia3.next();
	face[2] = apia3.getIndex()+1;
	if (face[2] > 11) {
		if (face[2] == 12) { face[2] = 0; } else { face[2] = 1; };
	}
	faceid = face[2];
	wintest();
});
$('#b1').live('click',function(){
	apib1.next();
	face[3] = apib1.getIndex()+1;
	if (face[3] > 11) {
		if (face[3] == 12) { face[3] = 0; } else { face[3] = 1; };
	}
	faceid = face[3];
	wintest();
});
$('#b2').live('click',function(){
	apib2.next();
	face[4] = apib2.getIndex()+1;
	if (face[4] > 11) {
		if (face[4] == 12) { face[4] = 0; } else { face[4] = 1; };
	}
	faceid = face[4];
	wintest();
});
$('#b3').live('click',function(){
	apib3.next();
	face[5] = apib3.getIndex()+1;
	if (face[5] > 11) {
		if (face[5] == 12) { face[5] = 0; } else { face[5] = 1; };
	}
	faceid = face[5];
	wintest();
});

} else {

/* SWIPE */

$('#a1').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apia1.next();
	face[0] = apia1.getIndex()+1;
    if (face[0] > 11) { if (face[0] == 12) { face[0] = 0; } else { face[0] = 1; };};
    faceid = face[0];
	wintest();
	},
	swipeRight: function() {
	apia1.prev();
	face[0] = apia1.getIndex()-1;
	if (face[0] == -1) { apia1.seekTo(12); };
    if (face[0] > 11) { if (face[0] == 12) { face[0] = 0; } else { face[0] = 1; };};
    if (face[0] < 0) { if (face[0] == -1) { face[0] = 11; } else { face[0] = 10; };};
	faceid = face[0];
	wintest();
	}
	});

$('#a2').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apia2.next();
	face[1] = apia2.getIndex()+1;
    if (face[1] > 11) { if (face[1] == 12) { face[1] = 0; } else { face[1] = 1; };};
    faceid = face[1];
	wintest();
	},
	swipeRight: function() {
	apia2.prev();
	face[1] = apia2.getIndex()-1;
	if (face[1] == -1) { apia2.seekTo(12); };
    if (face[1] > 11) { if (face[1] == 12) { face[1] = 0; } else { face[1] = 1; };};
    if (face[1] < 0) { if (face[1] == -1) { face[1] = 11; } else { face[1] = 10; };};
	faceid = face[1];
	wintest();
	}
	});

$('#a3').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apia3.next();
	face[2] = apia3.getIndex()+1;
    if (face[2] > 11) { if (face[2] == 12) { face[2] = 0; } else { face[2] = 1; };};
    faceid = face[2];
	wintest();
	},
	swipeRight: function() {
	apia3.prev();
	face[2] = apia3.getIndex()-1;
	if (face[2] == -1) { apia3.seekTo(12); };
    if (face[2] > 11) { if (face[2] == 12) { face[2] = 0; } else { face[2] = 1; };};
    if (face[2] < 0) { if (face[2] == -1) { face[2] = 11; } else { face[2] = 10; };};
	faceid = face[2];
	wintest();
	}
	});

$('#b1').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apib1.next();
	face[3] = apib1.getIndex()+1;
    if (face[3] > 11) { if (face[3] == 12) { face[3] = 0; } else { face[3] = 1; };};
    faceid = face[3];
	wintest();
	},
	swipeRight: function() {
	apib1.prev();
	face[3] = apib1.getIndex()-1;
	if (face[3] == -1) { apib1.seekTo(12); };
    if (face[3] > 11) { if (face[3] == 12) { face[3] = 0; } else { face[3] = 1; };};
    if (face[3] < 0) { if (face[3] == -1) { face[3] = 11; } else { face[3] = 10; };};
	faceid = face[3];
	wintest();
	}
	});

$('#b2').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apib2.next();
	face[4] = apib2.getIndex()+1;
    if (face[4] > 11) { if (face[4] == 12) { face[4] = 0; } else { face[4] = 1; };};
    faceid = face[4];
	wintest();
	},
	swipeRight: function() {
	apib2.prev();
	face[4] = apib2.getIndex()-1;
	if (face[4] == -1) { apib2.seekTo(12); };
    if (face[4] > 11) { if (face[4] == 12) { face[4] = 0; } else { face[4] = 1; };};
    if (face[4] < 0) { if (face[4] == -1) { face[4] = 11; } else { face[4] = 10; };};
	faceid = face[4];
	wintest();
	}
	});

$('#b3').swipe({threshold: {x: 44, y: 44},
	swipeLeft: function() {
	apib3.next();
	face[5] = apib3.getIndex()+1;
    if (face[5] > 11) { if (face[5] == 12) { face[5] = 0; } else { face[5] = 1; };};
    faceid = face[5];
	wintest();
	},
	swipeRight: function() {
	apib3.prev();
	face[5] = apib3.getIndex()-1;
	if (face[5] == -1) { apib3.seekTo(12); };
    if (face[5] > 11) { if (face[5] == 12) { face[5] = 0; } else { face[5] = 1; };};
    if (face[5] < 0) { if (face[5] == -1) { face[5] = 11; } else { face[5] = 10; };};
	faceid = face[5];
	wintest();
	}
	});

};
};

/* WINNER TEST */

function wintest() {

	if (justwon) {

		if (tscore <= (gocolor-1)) {
			$('#container #face img').each(function(){
				$(this).attr('src',$(this).attr('src').replace('_c.png','.png'));
			});
			$('body').css({background: '#fff'});
		}
	
		$('#container .winnertext').replaceWith('<div class=\"winnertext\">YOU DID IT!</div>');
		justwon = false;

	}

if (faceid == face[0] && faceid == face[1] && faceid == face[2] && faceid == face[3] && faceid == face[4] && faceid == face[5]) {
winner(); }

}

/* WINNER! */

function winner() {

	$('#face').fadeTo(11, 1, function() {
     $('#face').fadeTo(44, 1, function() {
      $('#face').fadeTo(22, 0, function() {
      $('body').css({background: '#000'});
   	   $('#face').fadeTo(22, 1, function() {
       $('body').css({background: '#fff'});
     	$('#face').fadeTo(22, 0, function() {
     	$('body').css({background: '#000'});
     	 $('#face').fadeTo(22, 1, function() {
     	 $('body').css({background: '#fff'});
     	  $('#face').fadeTo(44, 0, function() {
     	  $('body').css({background: '#000'});
     	   $('#face').fadeTo(22, 1, function() {
     	   $('body').css({background: '#fff'});
     		$('#face').fadeTo(44, 1, function() {
     		$('body').css({background: '#000'});
     		 $('#face').fadeTo(22, 1, function() {
     		 $('body').css({background: '#fff'});
     		  $('#face').fadeTo(44, 0, function() {
     		  $('body').css({background: '#000'});
     										
	if (completed[faceid] == faceid) {
		didit = true;
		} else {
		completed[faceid] = faceid;
	}
	
	if (didit) {
		didit = false;
		$('#container .winnertext').replaceWith('<div class=\"winnertext\"><EMBED src=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\" autostart=\"true\" type=\"audio/mpeg\" loop=\"false\" volume=\"16\" width=\"155\" height=\"22\" bgcolor=\"#000000\" controller=\"true\"><NOEMBED><BGSOUND src=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\"></NOEMBED><br /><span style=\"letter-spacing:.22em; line-height:2em; font-size:1.1em;\">' + facename[faceid] + ' LEVEL COMPLETE, AGAIN!</span><br /><br />You have won the ability to possess this as a free ring-tone!<br /><u>Right-click</u> below to download and/or continue to play the game.<br /><a href=\"ringtones/' + facename[faceid] + ' Level Complete.m4r\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .m4r, compatible with iPhones using iTunes. Drop this file into your iTunes Ringtone Library (left top-side of iTunes). Next time you sync your iPhone it should be transfered over and ringable. Make sure you click the Ringtones Library in the iPhone Sync preferences to transfer all that is added to it.\" class=\"ringtone\" target=\"_blank\">.m4r (iPhone)</a> | <a href=\"ringtones/' + facename[faceid] + ' Level Complete.aac\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .aac, compatible with most Sony Ericsson phones and some others. Drop it in the software you use to sync your phone." class=\"ringtone\" target=\"_blank\">.aac (Sony Ericsson)</a> | <a href="ringtones/' + facename[faceid] + ' Level Complete.amr\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .amr ringtone, compatible with mostly older Nokia phones. Drop it in the software you use to sync your phone." class=\"ringtone\" target=\"_blank\">.amr (older Nokia)</a><br /><a href=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .mp3 ringtone, compatible with most Android OS, most newer phones and music libraries alike.\" class=\"ringtone\" target=\"_blank\">.mp3 (Android OS, most current phones and mp3 players alike)</a></div>');
		} else {
		
		tscore++;
		
		$('#container .winnertext').replaceWith('<div class=\"winnertext\"><EMBED src=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\" autostart=\"true\" type=\"audio/mpeg\" loop=\"false\" volume=\"16\" width=\"155\" height=\"22\" bgcolor=\"#000000\" controller=\"true\"><NOEMBED><BGSOUND src=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\"></NOEMBED><br /><span style=\"letter-spacing:.22em; line-height:2em; font-size:1.1em;\">' + facename[faceid] + ' LEVEL COMPLETE!</span><br /><br />You have won the ability to possess this as a free ring-tone!<br /><u>Right-click links</u> to download and/or continue to play the game.<br /><a href=\"ringtones/' + facename[faceid] + ' Level Complete.m4r\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .m4r, compatible with iPhones using iTunes. Drop this file into your iTunes Ringtone Library (left top-side of iTunes). Next time you sync your iPhone it should be transfered over and ringable. Make sure you click the Ringtones Library in the iPhone Sync preferences to transfer all that is added to it.\" class=\"ringtone\" target=\"_blank\">.m4r (iPhone)</a> | <a href=\"ringtones/' + facename[faceid] + ' Level Complete.aac\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .aac, compatible with most Sony Ericsson phones and some others. Drop it in the software you use to sync your phone." class=\"ringtone\" target=\"_blank\">.aac (Sony Ericsson)</a> | <a href="ringtones/' + facename[faceid] + ' Level Complete.amr\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .amr ringtone, compatible with mostly older Nokia phones. Drop it in the software you use to sync your phone." class=\"ringtone\" target=\"_blank\">.amr (older Nokia)</a><br /><a href=\"ringtones/' + facename[faceid] + ' Level Complete.mp3\" title=\"' + facename[faceid] + ' Level Complete Ringtone! simply ctrl/right-click HERE to download this .mp3 ringtone, compatible with most Android OS, most newer phones and music libraries alike.\" class=\"ringtone\" target=\"_blank\">.mp3 (Android OS, most current phones and mp3 players alike)</a></div>');
}

	if (tscore <= gocolor) {

				$('#container #face img').each(function(){
				$(this).attr('src',$(this).attr('src').replace('.png','_c.png'));
				});

				$('#face').fadeTo(1600, 1, function() {});

	}
	
	else { $('#face').fadeTo(44, 1, function() {}); }
	
	justwon = true;
     	
     	  });
         });	
     	});
       });	
      });
     });
    });
   });
  });
 });
});

}

/* initialize face bits navigation == start the game! */
initclick();

});
