//jquery kolace
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


//$(document).ready(function(){
//Nastavim testovacie kolace
$.cookie("pixhosttest", "1", { path: '/', expires: 1 });

//Skontrolujem ci su ulozene testovacie kolace
if($.cookie("pixhosttest") == 1)
{
 //Skontrolujem ci existuju kolace, kt. ukladam pri klikani
 if($.cookie("pixhostads") != 1)
 {
  //vlozim reklamu
  $("div#js").html("<script src=\"/pixhost.js\" type=\"text/javascript\"></script><a style=\"color:blue;text-decoration:underline;cursor:pointer\">Continue to your image</a>");

  //skovam web
  $("div#web > *").hide();

  //skovam cerveny pasik
  $("span#bugs").hide();

  //skovam pozadie
  $("html body").css("background","none");

  //zobrazim div s reklamou
  $("div#js").show();

  //ak nastalo kliknutie nastavim kolace, skovam reklamu a zobrazim web
  $("div#js a").click(function(){

   //nastavim kolace
   $.cookie("pixhostads", "1", { path: '/', expires: 1 });

   //skovam reklamu
   $("div#js").hide();

   //nastavim pozadie
   $("body").css("background","#ffffff url('/image/background_image_header.gif') repeat-x");

   //zobrazim web
   $("div#web > *").fadeIn(250);

   //zobrazim cerveny pasik
   $("span#bugs").fadeIn(250);

  });
 }

 //zmazem testovacie kolace
 $.cookie("pixhosttest", null);
}
//});

/* Mazanie kolacov */
function delCookie(name, path, domain) 
{
 document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/* Ziskanie kolaca */
function getCookie(check_name)
{
 var a_all_cookies = document.cookie.split( ';' );
 var a_temp_cookie = '';
 var cookie_name = '';
 var cookie_value = '';
 var b_cookie_found = false;

 for ( i = 0; i < a_all_cookies.length; i++ )
 {
  a_temp_cookie = a_all_cookies[i].split( '=' );
  cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

  if ( cookie_name == check_name )
  {
   b_cookie_found = true;

   if ( a_temp_cookie.length > 1 )
   {
    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
   }

   return cookie_value;
   break;
  }
  a_temp_cookie = null;
  cookie_name = '';
 }

 if ( !b_cookie_found )
 {
  return null;
 }
}