// JavaScript Document
var userInfo=navigator.userAgent;

function jq_createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    jq_createCookie(name,"",-1);
}

function dismiss_warning(){
    jq_createCookie('jq_detect','safari_dismiss',1)//they have chosen to dismiss the warning. Create the dismiss cookie to last for one day.
    var alert_area=document.getElementById("browser_alert_contatiner");
    alert_area.innerHTML="";

}



function create_warning() {
var div = document.createElement('div');
    	div.id = 'browser_alert_contatiner';
		div.id = 'browser_alert_contatiner';
		div.setAttribute( 'style', 'background-color:#333; position: absolute; top:0px; left:0px; z-index: 9000; width:100%' );
		div.innerHTML='<div  style="padding:8px 10px; min-width:900px;">'
  + '<p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; text-align:center; color:#fff; "><strong>This site has advanced features that require Safari 3.0+, Firefox 2.0+, or Chrome 1.0+, and may not display properly in your browser.</strong></p>'
  + '<p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; text-align:center; color:#ccc; ">To experience this Web site as it was intended, please download one of these updated browsers and then revisit this site.</p>'
  + '<div   style="text-align:center;"><a href="http://www.apple.com/safari" target="_blank" style="margin-right:10px;"><img src="http://jellcreative.com/gbl_assets/images/download_safari.png" /></a>'
  + '<a href="http://www.mozilla.com/en-US/firefox/firefox.html" target="_blank" style="margin-right:10px;"><img src="http://jellcreative.com/gbl_assets/images/download_firefox.png" /></a>'
  + '<a href="http://www.google.com/chrome/" target="_blank" style="margin-right:50px;"><img src="http://jellcreative.com/gbl_assets/images/download_chrome.png" /></a>'
  + '<a onclick="dismiss_warning()"><img src="http://jellcreative.com/gbl_assets/images/no_thanks.png" style="cursor:pointer;" /></a></div>';
      	document.body.insertBefore(div, document.body.firstChild);
//document.body.appendChild(div);

}


function browserCheck() {
    
    //alert(userInfo)
    if(userInfo.indexOf('Safari')!=-1){//if this is safari
        if (userInfo.indexOf('Version/')!=-1 || userInfo.indexOf('Chrome/')!=-1){//if "Version/" or "Chrome"is in the userInfo string, this is safari 3 or higher or google chrome
            if (myCookie) {//if a cookie exists
            eraseCookie('jq_detect');//erase it. They have upgraded. Hooray!
            }
            
        //var version_str_loc=userInfo.lastIndexOf('Version/');//find occurance of version/
        //var start_str_loc=parseInt(version_str_loc+8)//Add 8 to the start and 1 to the end to grab major version number
        //var end_str_loc=start_str_loc+1;
        //var safari_majVer=userInfo.substring(start_str_loc, end_str_loc);//returns safari major version
    
            }//end if newer safari
            
            else{//This broswer is pre safari 3.0
                var myCookie = readCookie('jq_detect');
                if (myCookie) {//if a cookie exists
                        if(myCookie=='safari_dismiss'){//User has chosen to dismiss. ignore the browser and show no warning
                            }//end if cookie is dismiss
                        
                        else{//they have been flagged but have not explicitly chose to ignore. Show the warning again.
                   			create_warning()        
 

                        }//end flagged else
                }//end if cookie
                else{// if no cookie, set the cookie and show the warning
                    jq_createCookie('jq_detect','safari_warning',1);
					create_warning();
                
    
                    }//end else if cookie
    
            
            
                }//end else old safari
            }//end if safari
            else{//this is a not safari
                if (myCookie) {//if a cookie exists
                eraseCookie('jq_detect');//erase it. They have switched browsers. Hooray!
                }
            }
}

//document.onload = browserCheck;
//document.onload = create_warning;

//just in case the event fires before the body exists
function bodyLoaded(){
	if (document.body != null){
	browserCheck();
	clearInterval(body_check);
	}
}

var body_check = setInterval(bodyLoaded, 200)




