jQuery(document).ready(function(){

    jQuery('#add_bookmark').click(function () { // when object with id bookmark is clicked (navigate button)
      	jQuery('#add_bookmark_container_1').fadeIn(2000);
    });
    	
    jQuery("#add_bookmark_learn_more").click(function() { // when object with id learnMore is clicked
     	jQuery('#add_bookmark_container_5').fadeIn('fast');
    });

    jQuery("#add_bookmark_go_back").click(function() { // when object with id goBack is clicked
    	 jQuery('#add_bookmark_container_5').fadeOut('fast');
    	 jQuery('#add_bookmark_container_3').fadeIn('fast');
    });
});

function bookmarkNow() { // called if browser is supported by CreateBookmarkLink function
   		jQuery(document).ready(function(){
      		jQuery('#add_bookmark_first_text_1, #add_bookmark_second_text_1').fadeIn('fast');
  		});
	}
function unsupported() { // called if browser is not supported by CreateBookmarkLink function
   		jQuery(document).ready(function(){
   			jQuery('#add_bookmark_first_text_3, #add_bookmark_second_text_3, #add_bookmark_second_text').fadeIn('fast');
   			jQuery('#other2').fadeOut('fast');
   	  	});
	} 		
function Other() { // called if browser is not supported by CreateBookmarkLink function
   		jQuery(document).ready(function(){
   			jQuery('#add_bookmark_first_text_3, #add_bookmark_second_text_3').fadeIn('fast');
   	  	});
	}
	
function bookmarkNowOpera() { // called cause Opera v.10 does not support input type
   		jQuery(document).ready(function(){
      		jQuery('#add_bookmark_first_text_2, #add_bookmark_second_text_2').fadeIn('fast');
  		});
	}

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
	var ffversion=new Number(RegExp.$1); // capture x.x portion and store as a number
	if (ffversion>=1) { // Firefox 1.5 or greater
 		bookmarkNow();
	}
 	else {
  		Other();
 	}
}

else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for Internet Explorer x.x;
	var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
 	if (ieversion>=6) { // Internet Explorer 6 or greater
  		bookmarkNow();
 	}
 	else {
  		Other();
 	}
 	
}
else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
	var oprversion=new Number(RegExp.$1); // capture x.x portion and store as a number
 	if (oprversion>=9) { // Opera 10 or greater
  		bookmarkNowOpera();
 	}
 	else {
  		Other();
 	}
 	
}
else if (/SeaMonkey[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for SeaMonkey/x.x or SeaMonkey x.x (ignoring remaining decimal places);
 	var seaversion=new Number(RegExp.$1); // capture x.x portion and store as a number
 	if (seaversion>=1) {// SeaMonkey 1 or greater
 	 	bookmarkNow();
 	}
 	else {
  		Other();
 	}
}

else {
 	Other();
}
 
function CreateBookmarkLink() {
	
	bookmarkTitle(); // catch bookmark names from language file

   if (window.sidebar) { // required to work in firefox 1.5+
		window.sidebar.addPanel(title, url,"");     
		return closeMe();
   }

   else if( window.external ) { // required to work in ie6+
        window.external.AddFavorite(url, title);
		return closeMe();
   }
	
   	else if(window.opera && window.print) // required to work in opera 7+
    {
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar'); 
	    elem.click();
	    return closeMe();
    }
	
	else {
	}

}

function getCookie(cookieName) { // checking cookies value function
	if (document.cookie.length>0) {
		cookieBegin=document.cookie.indexOf(cookieName + "=");
		if (cookieBegin!=-1) {
			cookieBegin=cookieBegin + cookieName.length+1;
			cookieEnd=document.cookie.indexOf(";",cookieBegin);
		if (cookieEnd==-1) cookieEnd=document.cookie.length;
		return unescape(document.cookie.substring(cookieBegin,cookieEnd));
	  }
	}
	return "";
}

function setCookie(cookieName,value,expiredays) {  // creating cookie function
	var expires=new Date();
		expires.setDate(expires.getDate()+expiredays);
		document.cookie=cookieName+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+expires.toGMTString());
}

function closeMe() { // using this function when clicking submit with value CLOSE
	setCookie('firstVisit','firstVisit',-1); // removing firstVisit cookie
	setCookie('secondVisit','secondVisit',-1); // removing secondVisit cookie
	jQuery('#add_bookmark_container_1').fadeOut(2000); // fading popup after clicking submit with value CLOSE
}

function remindMeLater() { // using this function when clicking submit with value REMIND ME LATER
	setCookie('firstVisit','remindMeLater',7); // renaming firstVisit cookie value to REMIND ME LATER
	setCookie('secondVisit','remindMeLater',365); // waiting next session after clicking submit with value Remind me later
	jQuery('#add_bookmark_container_1').fadeOut(2000); // fading popup after clicking submit with value REMIND ME LATER
}

function checkCookie() { // body onload function

	var firstVisit=getCookie('firstVisit'); // getting cookie called firstVisit
	var secondVisit=getCookie('secondVisit'); // getting cookie called secondVisit
	var dailyVisitor=getCookie('dailyVisitor'); // getting cookie called dailyVisitor
	
	if(firstVisit=="" && secondVisit=="" && dailyVisitor=="") { // none of checked cookies does not exist
		setCookie('firstVisit','firstVisit'); // cookie expires after session ended
		setCookie('secondVisit','secondVisit', 365); // cookie is waiting second visit max. 1 year, otherwise will not annoy anymore
		setCookie('dailyVisitor','dailyVisitor', 3650); // cookie expires after 10 years from first visit, after that calls this if statement again
	}
	
	else if(firstVisit!="" && secondVisit!="" && dailyVisitor!="") { // do nothing, we don't want to annoy at the first time
	}
	
	else if(firstVisit!="remindMeLater" && secondVisit!="" && dailyVisitor!="") { // second visit, start annoying until clicked one of the options
		jQuery('#add_bookmark_container_1').fadeIn(2000);
		setTimeout("remindMeLater()",28000); // hide annoying window in 30 seconds (got already 2000ms fade from remindMeLater function) in this line 28000ms for 30000ms total
	}
	
	else if(firstVisit=="" && secondVisit=="" && dailyVisitor!="") {  // daily visitor, already annoyed
	}
	
	else {
	}
	
}