var Secrets_init;
var domain = 'http://' + window.location.hostname;
var pathname = window.location.href;
var id;
var enable = 1;

switch(pathname){
case domain + '/cdeprofile/leaderboards.html': id = 1; break;
case domain + '/dollmakers_stafffaves.html': id = 2; break;
case domain + '/cde_videos.html': id = 3; break;
case domain + '/cdeprofile/myblog_recent.html': id = 4; break;
case domain + '/cdeprofile/account.html': id = 5; break;
case domain + '/cdeprofile/avatar_hot_or_not.html': id = 6; break;
case domain + '/cdeprofile/store.html?st=b': id = 7; break;
case domain + '/cdeprofile/myblog_subcriber.html': id = 8; break;
case domain + '/cdeprofile/profile.html?id=63': id = 9; break;
case domain + '/cdeprofile/mypet.html': id = 10; break;
case domain + '/cdeprofile/signature.html': id = 11; break;
case domain + '/cdeprofile/clubs.html': id = 14; break;
default: id = 0;
}

$(document).ready(function(){
	if(Secrets_init.create == "true" && id != 0){
		showSecret();
		setSecret();
	}
	
	if(Secrets_init.type[0] == "search-text" && id != 0 && enable == 1){
		searchSecret();
	}
	
	if(Secrets_init.type[0] != "search-text"){
		$("#hiddensecret").click(function(){
			foundSecret();
		});
	}
	
	$("input#secretword").click(function(){ 
		this.select(); 
	});
});

function foundSecret()
{
	var stopfound = 0;
	
	if(Secrets_init.type[0] == "input-text"){
		var secretword = Secrets_init.type[1];
		var guessword = $("input#secretword").val();
		
		if(secretword != guessword){
			stopfound = 1;
			jAlert('Sorry. The secret word is incorrect. You may try again', 'CDE Hidden Secrets');
		}
	}

	if(stopfound == 0){
		$.ajax({
			type: "GET",
			url: "/cdeprofile/HiddenSecrets.php?action=foundSecret&secretid=" +id,
			success: function(msg){
				if(id == 9 || id == 5 || id == 3){
					alert(msg, 'CDE Hidden Secrets');
				}
				else{
					jAlert(msg, 'CDE Hidden Secrets');
				}
			}
		 });
		 
		 disableSecret();
	 }
}

function showSecret()
{

	if(Secrets_init.type[0] == "click-image"){
	    
	if(id==3 || id==5)
    {
        document.getElementById('secrets_hack').innerHTML=  '<div id="secretcontainer">' + '<a id="hiddensecret" ><img src="' +Secrets_init.type[1]+ '" alt="" /></a>' + '</div>';
    }
    else
    {
		$("BODY").append(
		  '<div id="secretcontainer" style="position:' +Secrets_init.position[0]+ '; left:' +Secrets_init.position[1]+ 'px; top:' +Secrets_init.position[2]+ 'px">' +
			'<a id="hiddensecret" ><img src="' +Secrets_init.type[1]+ '" alt="" /></a>' +
		  '</div>');
	 }
	}
	else if(Secrets_init.type[0] == "input-text"){
		$("BODY").append(
		  '<div id="secretcontainer" style="position:' +Secrets_init.position[0]+ '; left:' +Secrets_init.position[1]+ 'px; top:' +Secrets_init.position[2]+ 'px">' +
			'<input id="secretword" type="text" value="Guess the secret word" />' +
			'<div id="cdebutton"><a id="hiddensecret" style="cursor:pointer">Try Luck</a></div>' +
		  '</div>');
	}
}

function setSecret()
{
	$.ajax({
		type: "GET",
		url: "/cdeprofile/HiddenSecrets.php?action=isAlreadyFound&secretid=" +id,
		success: function(msg){
			if(msg != 0){
				disableSecret();
			}
		}
	 });
}

function disableSecret()
{
	if(Secrets_init.create == "true"){
		$("#secretcontainer").css({
			"display": "none"
		});
	}
	
	enable = 0;
}

function searchSecret()
{
	$.ajax({
		type: "GET",
		url: "/cdeprofile/HiddenSecrets.php?action=searchSecret&secretid=" +id+ "&searchword=" +Secrets_init.type[1],
		success: function(msg){
			if(msg != ''){
				jAlert(msg, 'CDE Hidden Secrets');
			}
		}
	 });
}

