var CP_BOX_DONE = false;
var CP_BOX_HEIGHT = 480;
var CP_BOX_WIDTH = 640;
var CP_BOX_DOMAIN = 'versme.dovanu-kuponai.lt';
var CP_BOX_COUPON_URL = 'http://versme.dovanu-kuponai.lt/coupons';
var CP_BOX_CODE = '12345678902';
var CP_BOX_ANIMATION = false;
var CP_BOX_LANGUAGE = 'lt';

var CP_BOX_hide = function(){};
var CP_BOX_show = function(){};

var jQueryScriptOutputted = false;
function initJQuery() {

    //if the jQuery object isn't available
    if (typeof(jQuery) == 'undefined') {

        if (! jQueryScriptOutputted) {
            //only output the script once..
            jQueryScriptOutputted = true;

            //output the script
            //document.write('<script type="text/javascript" src="http://'+CP_BOX_DOMAIN+'/js/jquery-1.4.2.js"></script>');
        }
        setTimeout("initJQuery()", 50);
    } else {

// JQuery is loaded








    
var GB_ANIMATION = true;
jQuery.noConflict();
jQuery(document).ready(function(){
	  
		    // Dovanu kuponai
		  //  alert('as');
	   jQuery.extend({
	    getUrlVars: function(){
	      var vars = [], hash;
	      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	      for(var i = 0; i < hashes.length; i++)
	      {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	      }
	      return vars;
	    },
	    getUrlVar: function(name){
	      return jQuery.getUrlVars()[name];
	    }
	  });
		    
	CP_BOX_show = function (caption, url, height, width) {
	
	  CP_BOX_WINDOW_HEIGHT = jQuery(document).height();
	  CP_BOX_WINDOW_WIDTH = jQuery(document).width();
	  if ( jQuery(window).height() > CP_BOX_WINDOW_HEIGHT){
		  CP_BOX_WINDOW_HEIGHT = jQuery(window).height();
	  }
	 // alert(CP_BOX_WINDOW_HEIGHT + "x" +CP_BOX_WINDOW_WIDTH);
	  if(!CP_BOX_DONE) {
	    jQuery(document.body)
	      .append("<div id='CP_BOX_overlay' style='background-color:#000000;opacity:0.5; filter: alpha(opacity=50);display:block;position: absolute;margin: auto;  top: 0;left: 0;z-index:99320;height:"+CP_BOX_WINDOW_HEIGHT+"px; width:100%;'></div>" +
      		"<div id='CP_BOX_window' style='display:block;top: 10px;left: 0px;position: absolute;background: #fff;border: 2px solid #aaa;overflow: hidden;width: 640px;height: 500px;z-index: 99335;'><div id='CP_BOX_caption' style='font: 12px bold helvetica, verdana, sans-serif;color: #fff;background: #888;padding: 2px 0 2px 5px;margin: 0;text-align: left;'></div>"
        + "<img style='position: absolute;  top: 2px;  right: 5px;  cursor: pointer;  cursor: hand;' src='http://"+CP_BOX_DOMAIN+"/api/img/close.gif' alt='Close window' /></div>");
   
	  
    
	  jQuery("#CP_BOX_window img").click(CP_BOX_hide);
	  jQuery("#CP_BOX_overlay").click(CP_BOX_hide);
	  jQuery(window).resize(CP_BOX_position);
	  jQuery(window).scroll(CP_BOX_position);
	  CP_BOX_DONE = true;
	}
        var lng = jQuery.getUrlVar('lng');

	if (typeof(lng)=='string' && isNaN(lng)){
		
		 CP_BOX_LANGUAGE = lng;
		
	}
	
	
	jQuery("#CP_BOX_frame").remove();
	jQuery("#CP_BOX_window").append("<iframe id='CP_BOX_frame' style='border: 0;overflow: hidden;height: 480px; width:640px;' src='"+url+"?&lng="+CP_BOX_LANGUAGE+"' ></iframe>");
      
	jQuery("#CP_BOX_caption").html(caption);
	jQuery("#CP_BOX_overlay").show();
	CP_BOX_position();
      
	if(CP_BOX_ANIMATION)
	  jQuery("#CP_BOX_window").slideDown("slow");
	else
	  jQuery("#CP_BOX_window").show();
      }
      
      CP_BOX_hide = function () {
	jQuery("#CP_BOX_window,#CP_BOX_overlay").hide();
	if (typeof(App) == 'object'  && typeof(App.ds) == 'object'  && typeof(App.ds.cpcoupons) == 'object' ){
	      App.ds.cpcoupons.reload();  
	}
	
      }
      
      function CP_BOX_position() {
	var de = document.documentElement;
	var scrollTop = 10 ;//+ jQuery(window).scrollTop();
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	//jQuery("#CP_BOX_window").css({width:CP_BOX_WIDTH+"px",height:CP_BOX_HEIGHT+"px",
	 // left: ((w - CP_BOX_WIDTH)/2)+"px" });
	jQuery("#CP_BOX_window").css({top : scrollTop+"px", left: ((w - CP_BOX_WIDTH)/2)+"px" });
	//jQuery("#CP_BOX_frame").css("height",CP_BOX_HEIGHT - 20 +"px");
      }


	  
	jQuery("#dovanu-kuponai").unbind();
	jQuery("#dovanu-kuponai").click(function(){
	  var t = this.title || jQuery(this).text() || this.href;
	
		  CP_BOX_show('Naujas dovanų kuponas',this.href,500,640);
	  return false;
	});
	
	  jQuery(".dovanu-kuponai").unbind();
	jQuery(".dovanu-kuponai").click(function(){
	  var t = this.title || jQuery(this).text() || this.href;
	
		  CP_BOX_show('Naujas dovanų kuponas',this.href,500,640);
	  return false;
	});
	
	
	var orderid = jQuery.getUrlVar('orderid');
	if (typeof(orderid)=='string' && isNaN(orderid) && orderid.length == 32){
			
		 CP_BOX_show('Naujas dovanų kuponas',CP_BOX_COUPON_URL+'/index/accept/orderid/'+orderid,500,640);
		
	}
	var dovanu_kuponai = jQuery.getUrlVar('dovanu_kuponai');
	
	if (typeof(dovanu_kuponai)=='string' && isNaN(dovanu_kuponai) && dovanu_kuponai == 'show'){
		
		 CP_BOX_show('Naujas dovanų kuponas',CP_BOX_COUPON_URL, 500,640);
		
	}

});






// END is loaded

    }

}
initJQuery();





