$(document).ready(function(){
	// animate quotes player
	animateQuotePlayer();
	
	// for safari
	detect = navigator.userAgent.toLowerCase();
	if (checkIt('safari') || checkIt('opera')) {
		$("div.top-player").css({left:"-9px"});
	}	
	$("#prev_link").click( function() {
	previousQuote();
	});

	$("#next_link").click( function() {
		nextQuote();
	});	

});

var quoteObj =  {"quoteObjectArray":[
     {
     "Quote":"&quot;This application basically rocks. I can barely remember my own wife&#39;s birthday, let alone all my family members. Now it&#39;s easy to look like the sensitive caring dude even if I&#39;m not.&quot;",
     "Name":"Justin Bookey",        
     "Location":"Los Angeles,&nbsp;CA"
     },
     {
     "Quote":"&quot;This application is great. I love that it automatically adds birthdays, that way I only have to add the other things.&quot;",
     "Name":"Ariana L.",        
     "Location":"Washington, DC"
     },
     {
     "Quote":"&quot;Since I use Facebook on a daily basis this is good for me to be able to remember certain things/event/holidays I want/need to.&quot;",
     "Name":"Julie Anderson",        
     "Location":"Australia"
     },
     {
     "Quote":"&quot;This is a fantastic way to keep track of our daily things...plus all our family and friends birthdays...NICE!&quot;",
     "Name":"Sylvia Garcia",        
     "Location":""
     },
     {
     "Quote":"&quot;Seems like a pretty interesting application. I just sent out 18 invites to some of my friends/relatives and their birthdays are listed there, I also added in holidays as well as my anniversary.&quot;",
     "Name":"Matthew Matlock",        
     "Location":"Halifax, NS"
     },
      {
     "Quote":"&quot;Haven&#39;t even been using it an hour but already impressed with how easy it is to add events.&quot;",
     "Name":"Tammy Perrault",        
     "Location":"Concord, NH"
     },
     {
     "Quote":"&quot;I like its simplicity. It&#39s so easy to keep track of anything on this calendar.&quot;",
     "Name":"Mya Isabelle Aubin",        
     "Location":" Vancouver, BC"
     }
     
    ]};

// browser details
var detect;

// array contains names of player links
var playerObjectIndex = 0;
var len = quoteObj.quoteObjectArray.length;
var playInterval = 10000;
function animateQuotePlayer() {
	setQuote(playerObjectIndex);
	playerObjectIndex =playerObjectIndex + 1;
	if(playerObjectIndex > (len-1)) {
		playerObjectIndex = 0;
	}
	t=setTimeout("animateQuotePlayer()",playInterval);
}

function nextQuote() {
	setQuote(playerObjectIndex);
	playerObjectIndex =playerObjectIndex + 1;
	if(playerObjectIndex > (len-1)) {
		playerObjectIndex = 0;
	}
	
}

function previousQuote() {
	prevIndex=playerObjectIndex;
	playerObjectIndex= playerObjectIndex - 1;
	if(playerObjectIndex < 0) {
		playerObjectIndex =0;
	}
	setQuote(playerObjectIndex);	
}

function setQuote(playerObjectIndex) {
	$("#play-quote").html(quoteObj.quoteObjectArray[playerObjectIndex].Quote);
	$("#quote-user-name").html(quoteObj.quoteObjectArray[playerObjectIndex].Name+"<br/>"+quoteObj.quoteObjectArray[playerObjectIndex].Location);
}

// check for different browser
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	return place;
}
function ajaxRequest(method, url, data, successHandler, failureHandler, formId, asyncType, responseType){
    if(formId)
        var dataString = $('#'+formId).serialize();
    else 
        var dataString = data;
        
    $.ajax({
         url: url,
         //GET method is used
         type: method,
          
         //pass the data        
         data: dataString,    
          
         //Do not cache the page
         cache: false,
          
         //success
         success: successHandler,
         
         //failure
         error: failureHandler,
         
         async: asyncType,
         
         dataType: responseType
     });
}
