/* ------------------------------------------------------------------------
prettyCheckboxes

Developped By: Stephane Caron (http://www.no-margin-for-errors.com)
Inspired By: All the non user friendly custom checkboxes solutions ;)
Version: 1.1

Copyright: Feel free to redistribute the script/modify it, as
long as you leave my infos at the top.
------------------------------------------------------------------------- */

jQuery.fn.prettyCheckboxes = function(settings) {
settings = jQuery.extend({
checkboxWidth: 19,
checkboxHeight: 19,
className : 'prettyCheckbox',
display: 'list'
}, settings);

$(this).each(function(){
// Find the label
$label = $('label[for="'+$(this).attr('id')+'"]');

// Add the checkbox holder to the label
$label.prepend("<span class='holderWrap'><span class='holder'></span></span>");

// If the checkbox is checked, display it as checked
if($(this).is(':checked')) { $label.addClass('checked'); };

// Assign the class on the label
$label.addClass(settings.className).addClass($(this).attr('type')).addClass(settings.display);

// Assign the dimensions to the checkbox display
$label.find('span.holderWrap').width(settings.checkboxWidth).height(settings.checkboxHeight);
$label.find('span.holder').width(settings.checkboxWidth);

// Hide the checkbox
$(this).addClass('hiddenCheckbox');

// Associate the click event
$label.bind('click',function(){
$('input#' + $(this).attr('for')).triggerHandler('click');

if($('input#' + $(this).attr('for')).is(':checkbox')){
$(this).toggleClass('checked');
$('input#' + $(this).attr('for')).checked = true;

$(this).find('span.holder').css('top',0);
}else{
$toCheck = $('input#' + $(this).attr('for'));

// Uncheck all radio
$('input[name="'+$toCheck.attr('name')+'"]').each(function(){
$('label[for="' + $(this).attr('id')+'"]').removeClass('checked');	
});

$(this).addClass('checked');
$toCheck.checked = true;
};
});

$('input#' + $label.attr('for')).bind('keypress',function(e){
if(e.keyCode == 32){
if($.browser.msie){
$('label[for="'+$(this).attr('id')+'"]').toggleClass("checked");
}else{
$(this).trigger('click');
}
return false;
};
});
});
};

checkAllPrettyCheckboxes = function(caller, container){
if($(caller).is(':checked')){
// Find the label corresponding to each checkbox and click it
$(container).find('input[type=checkbox]:not(:checked)').each(function(){
$('label[for="'+$(this).attr('id')+'"]').trigger('click');
if($.browser.msie){
$(this).attr('checked','checked');
}else{
$(this).trigger('click');
};
});
}else{
$(container).find('input[type=checkbox]:checked').each(function(){
$('label[for="'+$(this).attr('id')+'"]').trigger('click');
if($.browser.msie){
$(this).attr('checked','');
}else{
$(this).trigger('click');
};
});
};
};

(function($){
$.unserialise = function(Data){
        var Data = Data.split("&");
        var Serialised = new Array();
        $.each(Data, function(){
            var Properties = this.split("=");
            Serialised[Properties[0]] = Properties[1];
        });
        return Serialised;
    };
})(jQuery);

 var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
      if (base64test.exec(input)) {
         alert("There were invalid base64 characters in the input text.\n" +
               "Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" +
               "Expect errors in decoding.");
      }
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
   }


/**================== T A K E O V E R - S T A R T ===============================**/

var TAKEOVER_RICHMEDIA = {
xmlFile: "",
clickTag: "",

 /**
 * @author mahmut bayri rev: 08.03.2011
 * flash embed code
 */
 parseTakeOver: function () {
   var flashCode = "";
   flashCode += "<object codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=5,0,0,0\" width=\"100%\" height=\"100%\">";
   flashCode += "<param name=\"movie\" value=\"http://www.vomedia.tv/adunits/Takeover.swf\" />";
   flashCode += "<param name=\"quality\" value=\"high\" />";
   flashCode += "<param name=\"wmode\" value=\"transparent\" />";
   flashCode += "<param name=\"menu\" value=\"false\" />";
   flashCode += "<param name=\"scale\" value=\"noscale\" />";
   flashCode += "<param name=\"wmode\" value=\"transparent\" />";
   flashCode += "<param name=\"allowscriptaccess\" value=\"always\" />";
   flashCode += "<param name=\"allownetworking\" value=\"all\" />";
   flashCode += "<param name=\"id\" value=\"takeOverFlashBanner\" />";
   flashCode += "<param name=\"quality\" value=\"best\" />";
   flashCode += "<param name=\"flashvars\" value=\"config="+this.xmlFile+"&"+this.clickTag+"\" />";
   flashCode += "<embed name=\"takeOverFlashBanner\" flashvars=\"config="+this.xmlFile+"&"+this.clickTag+"\" allownetworking=\"all\" allowscriptaccess=\"always\" wmode=\"transparent\" width=\"100%\" height=\"100%\" scale=\"noscale\" menu=\"false\" src=\"http://www.vomedia.tv/adunits/Takeover.swf\" quality=\"best\"  type=\"application\/x-shockwave-flash\" wmode=\"transparent\" pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\"><\/embed>";
   flashCode += "<\/object>";
   return flashCode;
 },
 /**
 * @author mahmut bayri rev: 08.03.2011
 * generate container
 */
 generateTakeOverContainer: function (xml,clickTag) {

if(xml !== undefined || xml !== ""){
	
	this.xmlFile = xml;
	this.clickTag = clickTag;
    this.closeTakeOver();
    var mainBody = document.getElementsByTagName('body')[0];
    var takeOverContainer = document.createElement('div');
    
    takeOverContainer.id = "takeOverContainer";
    
    var styleElement = takeOverContainer.style;
    styleElement.position = "fixed";
    styleElement.width = "100%",
    styleElement.height = "100%";
    styleElement.zIndex = "2147483646";
    styleElement.top = "0px";
    styleElement.left = "0px";
    
    var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

    if(isIE6 !== false){
      styleElement.position = "absolute";
      styleElement.height = "900px";
    }
    
    takeOverContainer.innerHTML = this.parseTakeOver();
    mainBody.appendChild(takeOverContainer);
}
 },
 /**
 * @author mahmut bayri rev: 08.03.2011
 * close take over
 */
 closeTakeOver: function () {
   var mainBody = document.getElementsByTagName('body')[0];
   try{
     var takeOverContainer = document.getElementById("takeOverContainer");
     takeOverContainer.innerHTML = "";
         mainBody.removeChild(takeOverContainer);
         }catch(err){
           
         }
     }
   };

   function close_takeover() {
     TAKEOVER_RICHMEDIA.closeTakeOver();
   }
   
   /**================== T A K E O V E R - E N D ===============================**/

