 


Exit24 = {

	"init" : function ()
	{
    Shadowbox.init({
      'enableKeys':false,
      'displayNav':false,
      'autoDimensions': true
    });
	}

}
/*
$(function () {
	Exit24.init();
});
*/
////////////////////////////

var Cookie = {
  set: function ( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
      expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
      ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
      ( ( path )    ? ";path="    + path : "" ) +
      ( ( domain )  ? ";domain="  + domain : "" ) +
      ( ( secure )  ? ";secure" : "" );
  },

  get: function( 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;
  	}
  },

  remove: function( name, path, domain ) {
    if ( Get_Cookie( name ) ) {
      document.cookie = name + "=" +
      ( ( path ) ? ";path=" + path : "") +
      ( ( domain ) ? ";domain=" + domain : "" ) +
      ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
  }

}

Exit24.showPanel = function( module, panelName, width, height, parameters ) {
  $.post(
    URI_ROOT + 'action/' + module + '/getPanel/' + panelName,
    parameters,
    function(responseText){
      Shadowbox.open({
        player:  'html',
        content: responseText,
        width:   width || 686,
        height:  height || 490
      });
      $('.bk_banner_custom').css({visibility:'hidden'});
      Shadowbox.applyOptions({
        onClose: function() {
          $('.bk_banner_custom').css({visibility:''});
        }
      });
    }
  );
}

Exit24.sendArticle = function( _form, articleID ) {
  var errors = [];
  if ( !_form['email-to'].value ) {
    $( _form['email-to'] ).addClass('error');
    errors.push('Nem adtad meg a címzettet');
  }
  if ( errors.length == 0 ) {
    Exit24.showPanel( 'article', 'sendEmail/' + articleID, 0, 200, {
      to: _form['email-to'].value,
      toname: _form['email-toname'].value,
      fromname: _form['email-fromname'].value,
      from: _form['email-from'].value,
      desc: _form['email-description'].value
    });
  } else {
    $('.bk_articles_sendMailPanel .errors').html( errors.join('<br'+'/>' ) );
  }
}

Exit24.articleRating = {
  isRated: function( articleID ) {
    _rates = Cookie.get('article_rates');
    if ( _rates ) {
      ratedArticles = _rates.split(',');
      if ( ratedArticles.indexOf( articleID.toString() ) > -1 ) {
        return true;
      }
    }
    return false;
  },

  rate: function( articleID, point, _count, _sum ) {
    if ( Exit24.articleRating.isRated( articleID ) ) {
      return false;
    }

    $.post( URI_ROOT + 'action/article/rate',
       { 'articleID': articleID, 'point': point },
      function( responseText ) {
        //Exit24.articleRating.disable();
        _rates = Cookie.get('article_rates');
        if ( !_rates ) {
          _rates = articleID;
        } else {
          _rates += ',' + articleID;
        }
        Cookie.set( 'article_rates', _rates );
        _count++;
        _sum += point;
        $('.tools .rating div.disabled span').css({width: Math.round( ( _sum / _count ) * 14 ) + 'px'});
      }
    );
  },

  init: function( articleID, _count, _sum ) {
    articleID = articleID.toString();
    if ( !Exit24.articleRating.isRated( articleID ) ) {

      $('.tools .rating div.enabled').hide();

      $('.tools .rating').hover(function() {
        if ( !Exit24.articleRating.isRated( articleID ) ) {
          $('.tools .rating div.disabled').hide();
          $('.tools .rating div.enabled').show();
        }
      },function() {
          $('.tools .rating div.disabled').show();
          $('.tools .rating div.enabled').hide();
      });
      $('.tools .rating a span').click(function( event ) {
        _span = this;
        point = parseInt( _span.className.substring( 1, 2 ) ) + 1;
        Exit24.articleRating.rate( articleID, point, _count, _sum );
      });

    } else {

      $('.tools .rating div.enabled').hide();
      $('.tools .rating div.disabled').show();

    }

  }

}
Exit24.init();
