/*
 * Copyright (C) 2012 PrimeBox (info@primebox.co.uk)
 * 
 * This work is licensed under the Creative Commons
 * Attribution 3.0 Unported License. To view a copy
 * of this license, visit
 * http://creativecommons.org/licenses/by/3.0/.
 * 
 * Documentation available at:
 * http://www.primebox.co.uk/projects/cookie-bar/
 * 
 * When using this software you use it at your own risk. We hold
 * no responsibility for any damage caused by using this plugin
 * or the documentation provided.
 */
(function(e){e.cookieBar=function(t,n){if(t=="cookies"){var r="cookies"}else if(t=="set"){var r="set"}else{var r=false}var i={message:"We use cookies to track usage and preferences.",acceptButton:true,acceptText:"I Understand",declineButton:false,declineText:"Disable Cookies",policyButton:false,policyText:"Privacy Policy",policyURL:"/privacy-policy/",autoEnable:true,expireDays:365,forceShow:false,effect:"slide",element:"body",append:false,fixed:false,redirect:String(window.location.href),domain:String(window.location.hostname)};var t=e.extend(i,t);var s=new Date;s.setTime(s.getTime()+t.expireDays*24*60*60*1e3);s=s.toGMTString();var o="cb-enabled={value}; expires="+s+"; path=/";var u,a="",f,l=document.cookie.split("; ");for(u=0;u<l.length;u++){f=l[u].split("=");if(f[0]=="cb-enabled"){a=f[1]}}if(a==""&&t.autoEnable){a="enabled";document.cookie=o.replace("{value}","enabled")}if(r=="cookies"){if(a=="enabled"||a=="accepted"){return true}else{return false}}else if(r=="set"&&(n=="accepted"||n=="declined")){document.cookie=o.replace("{value}",n);if(n=="accepted"){return true}else{return false}}else{var c=t.message.replace("{policy_url}",t.policyURL);if(t.acceptButton){var h='<a href="" class="cb-enable">'+t.acceptText+"</a>"}else{var h=""}if(t.declineButton){var p='<a href="" class="cb-disable">'+t.declineText+"</a>"}else{var p=""}if(t.policyButton){var d='<a href="'+t.policyURL+'" class="cb-policy">'+t.policyText+"</a>"}else{var d=""}if(t.fixed){var v=' class="fixed"'}else{var v=""}if(t.forceShow||a=="enabled"||a==""){if(t.append){e(t.element).append('<div id="cookie-bar"'+v+"><p>"+c+h+p+d+"</p></div>")}else{e(t.element).prepend('<div id="cookie-bar"'+v+"><p>"+c+h+p+d+"</p></div>")}}e("#cookie-bar .cb-enable").click(function(){document.cookie=o.replace("{value}","accepted");if(a!="enabled"&&a!="accepted"){window.location=t.currentLocation}else{if(t.effect=="slide"){e("#cookie-bar").slideUp(300,function(){e("#cookie-bar").remove()})}else if(t.effect=="fade"){e("#cookie-bar").fadeOut(300,function(){e("#cookie-bar").remove()})}else{e("#cookie-bar").hide(0,function(){e("#cookie-bar").remove()})}return false}});e("#cookie-bar .cb-disable").click(function(){var n=new Date;n.setTime(n.getTime()-864e6);n=n.toGMTString();l=document.cookie.split("; ");for(u=0;u<l.length;u++){f=l[u].split("=");if(f[0].indexOf("_")>=0){document.cookie=f[0]+"=0; expires="+n+"; domain="+t.domain.replace("www","")+"; path=/"}else{document.cookie=f[0]+"=0; expires="+n+"; path=/"}}document.cookie=o.replace("{value}","declined");if(a=="enabled"&&a!="accepted"){window.location=t.currentLocation}else{if(t.effect=="slide"){e("#cookie-bar").slideUp(300,function(){e("#cookie-bar").remove()})}else if(t.effect=="fade"){e("#cookie-bar").fadeOut(300,function(){e("#cookie-bar").remove()})}else{e("#cookie-bar").hide(0,function(){e("#cookie-bar").remove()})}return false}})}}})(jQuery)