// JavaScript Document

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function ShowAll(){
  $(".appear, #FirstLine h1, #SecondLine h1, #InstrLine p, #PlayIntro").show();	
};
	
function IntroAnim(){		
  setTimeout(function(){	
	$("#FraudWrap").append("<div class='homeCover' id='FraudCover'></div>").children('#FraudCover').hide().slideDown(2000).effect("highlight",{},1000).slideUp(2000);
	$("#SearchWrap").append("<div class='homeCover' id='SearchCover'></div>").children('#SearchCover').hide().slideDown(2000).effect("highlight",{},1000).slideUp(2000);		  
	$("#RecoveryWrap").append("<div class='homeCover' id='RecoveryCover'></div>").children('#RecoveryCover').hide().slideDown(2000).effect("highlight",{},1000).slideUp(2000);	  
  },1000);	
  setTimeout(function(){$(".appear").show()},3100);
  setTimeout(function(){$("#FirstLine h1").show("slide",{ direction:"left" },500).effect("shake", { distance:2 }, 200)},5500);
  setTimeout(function(){$("#SecondLine h1").show("slide",{ direction:"right" },500).effect("shake", { distance:2 }, 200)},8000);
  setTimeout(function(){$("#InstrLine p").fadeIn(1500)},10500);
  setTimeout(function(){$("#PlayIntro").fadeIn(500)},13500);
};

function GoFraud(){window.location = "FraudCenter_1.html"};

function GoRecovery(){window.location = "PremiumRecovery_1.html"};

function GoSearch(){window.location = "SearchNews_1.html"};

function HideAll(){
	$(".appear, #FirstLine h1, #SecondLine h1, #InstrLine p, #PlayIntro").fadeOut(500);
	$(".homeCover").remove();	
};

 var RepeatVisit = cookieVal("WCA_Intro");                       //Gets value of cookie name "WCA_Intro"
 var RepeatVal = parseFloat(RepeatVisit);                        // Turns cookie value from string to number

 
  function cookieVal(cookieName) {                               //Function for determining value of given cookie name.  
	var thisCookie = document.cookie.split("; ");	
	for (var i=0; i<thisCookie.length; i++) {
		if(cookieName == thisCookie[i].split("=")[0])
		{
		 return thisCookie[i].split("=")[1];
		}									  
	}
	return 0;
 };

$(function (){	
			
  if (RepeatVal == 1){                                      //If the repeat visiter cookie is set to one, Show all elements without animation.
	ShowAll();
  }		
  else {                                                    //If the repeat visitor cookie has any other value (which will be zero), run animation.
 	IntroAnim();
  };
 
  $('.picWrap').hover(function() {
	  $(this).children('.front').stop().animate({ "top" : '325px'}, 700); 
	}, function() {
	  $(this).children('.front').stop().animate({ "top" : '28px'}, 400);       
  });
	  
  $("#FraudDetails").click(function(){
	GoFraud();			   
  });
  
  $("#SearchDetails").click(function(){
	GoSearch();			   
  });
	
  $("#RecoveryDetails").click(function(){
	GoRecovery();			   
  });	
  
  $("#PlayIntro").click(function(){
  	HideAll();
	IntroAnim();
  });
  
  $(window).unload(function(){                       //Sets intro cookie on page unload
			$.cookie('WCA_Intro','1',{expires: 1})
  });
  
});

/*	
setTimeout(function(){	
	$(".picWrap").append("<div class='homeCover' id='FraudCover'></div>").children('.homeCover').hide().css("top","-251px").show().animate({"top":'29px'},2000).effect("highlight",{},1000).animate({"top":'-251px'},2000)},1000);

This funtion works for taking out all jquery UI dependencies except hightlight.  Not changes to the CSS file to make it work.  

*/	
/*
	setTimeout(function(){$("#FirstLine h1").css({'margin-left':'-10em','margin-right':'auto'}).show().animate({"marginLeft":'500px'},500)},5500);
	setTimeout(function(){$("#SecondLine h1").show("slide",{ direction:"right" },500).effect("shake", { distance:2 }, 200)},8000);
	
	Trying to take out jquery UI for initial animation.  The first line works but MarginLeft will not provide a value of "auto" so I will have to get the 		parent window width in order to center the text on animate
*/