(function(){
    var cynergy_cookie = (function(){
        return {
            //defaults properties
            expiration: 180, // default days to expire
            cookieName: 'cyn_retarget',
            domain: '.cynergy.com',


            set_cookie: function(name, value, expiration, domain){
                // capturing the current time and checking for defaults
                var timestamp = new Date(),
                    expiration = (typeof expiration === 'undefined') ? this.expiration : expiration,
                    domain = (typeof domain === 'undefined') ? this.domain : domain;
                timestamp.setTime(timestamp.getTime() + (expiration * 24 * 60 * 60 * 1000));

                //set the cookie
                document.cookie = name + '=' + value + ';expires=' + timestamp.toGMTString() + '; path=/;domain=' + domain+';';
            }, 
            capture_info: function(paramName, cookieName){

                // gathering URL and checking defaults
                var location = window.location.href.toLowerCase(), paramValue, paramLocation, 
                    cookieName = (typeof cookieName === 'undefined') ? this.cookieName : cookieName;
                paramLocation =  location.indexOf(paramName);

                // analyzing the URL and isolating the value of query string "paramName"
                if (paramLocation > 0){
                    paramValue = location.substr(paramLocation+paramName.length+1);
                    if (paramValue.indexOf('&') !== -1) {
                        paramValue = location.substring(0, paramValue.indexOf('&'));
                    }

                    this.set_cookie(cookieName, paramValue);
                } // if paramLocation
            }  // cpature_info
        }
    }());  //cynergy_cookie

    cynergy_cookie.capture_info('cyn_retarget');
}());
