/**
 * PixmaCMS
 *
 * LICENSE
 *
 * This source file is subject to the GPL license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @package		PixmaCMS
 * @copyright	Copyright © 2009, PixmaSoft OÜ (http://www.pixmasoft.ee)
 * @license		http://www.gnu.org/licenses/gpl.txt     GPL  
 */

/**
 * A class that consist main PixmaCMS javascript functions. Through this class,
 * other javascript scripts get system config, translations and useful functions.
 *  
 * @class		PixmaCMS
 * @author		Raido Orumets <raido@pixmasoft.ee>
 * @created		2009-06-15
 * @modified	2009-08-23
 * @version		0.2 2009-06-15
 */

PixmaCMS = {
	
	init: function(){
				
		if(PixmaCMS.config.disable_copying){
			PixmaCMS.disableCopying();
		}
				
		$("input").defaultValue();
		$("input").keypress(function (event){ return (event.keyCode == 13)?$(this).parents("form:first").submit():true; });
		$("#search form img").click(function(){ $(this).parents("form:first").submit(); });
		$(".newsletter_button").click(function(){ $(this).parents("form:first").submit(); });
		if($("#left").height() <= $("#right").height()){
			$("#left").height($("#right").height());
		} else {
			$("#right").height($("#left").height());
		}
		PixmaCMS.backToTop();
		
		//$(document).pngFix({ blankgif:'img/blank.gif' });
		
		$('#to_top_button').click(function(){ $('html, body').animate({scrollTop:0}, 'slow'); });
		
		// $('input[type=radio].rating_star').rating({
		/*$('input.rating_star').rating({
			required: true,
			callback: function(value, link){
		
			},
			focus: function(value, link){
				var tip = $('.rating_title', this.form);
				tip[0].data = tip[0].data || tip.html();
				tip.html(link.title || 'value: '+value);
			},
			blur: function(value, link){
				var tip = $('.rating_title', this.form);
				$('.rating_title').html(tip[0].data || '');
			}
		});*/

	},
	
	redirect: function(url){
		window.location.href = url;
	},
	
	nospam: function(user, domain) {
		window.location = "mailto:" + user + "@" + domain;
	},
	
	smilie: function(smilietext, form, name) {
		eval('document.' + form + '.' + name + '.value += "' + smilietext + ' ";');
	},
	
	array_repair: function(_array){
		var array = new Array();
		for (var i in _array){
			array[array.length] = _array[i];
		}
		
		return array;
	},
	
	disableCopying: function(){
		$(document).bind("contextmenu", function(e){return false;});
		$(document).disableTextSelect();
	},
	
	enableCopying: function(){
		$(document).unbind("contextmenu");
		$(document).enableTextSelect();
	},
	
	backToTop: function(){
				
		$('<div>').hide().attr('id', 'toTop')
			.css('background-color', '#000000')
			.css('position', 'absolute')
			.css('color', '#FFFFFF')
			.css('font-size', '10px')
			.css('padding', '6px')
			.css('padding-left', '30px')
			.css('padding-right', '30px')
			.css('position', 'fixed')
			.css('bottom', '0px')
			.css('right', '0px')
			.css('cursor', 'pointer')
			.css('line-height', 'normal')
			.css('z-index', '1000')
			//.css('opacity', '0.7')
			//.css('filter', 'alpha(opacity=70)')
			//.css('-moz-opacity', '0.7')
			.html('tagasi &uuml;les')
			.appendTo('body');
			
		$(window).scroll(function(){
			if($(this).scrollTop() != 0){
				$('#toTop').fadeIn('fast');
			} else {
				$('#toTop').fadeOut('slow');
			}
		});
		
		$('#toTop').click(function () {
			$('html, body').animate({scrollTop:0}, 'slow');
		});
	}
}

PixmaCMS.config = {
	
	url: "/",
	language: "ee",
	country: "ee",
	disable_copying: false
}

PixmaCMS.text = {
	
	//TODO
}

$(function() {
	PixmaCMS.init();
});
