/*
 * jQuery WG Rotate plug-in 1.0
 * Copyright (c) 2008 Roberto Lee (webgenerator.nl)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2009-04-02
 * Rev: 1
 */
 (function($){
     $.fn.extend({
         WG_Rotate: function(options) {
	        var defaults = {
				source_container: '',
				type: 'cycle', 							//cycle, random  //cycling needs the cycling plugin http://malsup.com/jquery/cycle/
				cycle_fx: 'fade', 				//fade,scrollDown,scrollUp,scrollLeft,scrollRight
				cycle_speed: 1500,
				cycle_timeout: 4000,
				cycle_random: 1,
				content_align: 'left',
				cb: function(){}
	        };
	        var options = $.extend(defaults, options);

            return $(this).each(function(idx) {// Don't break the chain
				html_elem = this;

				if((($(html_elem)).is('*')) && ($(options.source_container).is('*')))
				{
					//$.log($(options.source_container).html());
					var rot_items = $(options.source_container + ' img,' + options.source_container + ' li').not('li img');
					var holder_items = $('<div/>');

					rot_items.siblings('img').each(function () {
						var item = $('<img/>').attr({
								      			'src': $(this).attr('src'),
								      			'border' : '0'
								      			})
					  	holder_items.append($('<div/>').addClass('rot_item').append(item));
					});

					rot_items.siblings('li').each(function () {
					  	if(($.trim($(this).html())).length > 0)
					  	{
							holder_items.append($('<div/>').addClass('rot_item').append($(this).html()));//$.log($.trim($(this).html()));
						}
					});

					rot_items = holder_items.find('div.rot_item').css({
														      			'margin': '0px',
														      			'padding' : '0px',
														      			'text-align' : options.content_align
														      			}); //$.log(holder_items.html());

					if (rot_items.length <= 1)	{$.log('Too few items ' + options.source_container + "=" + rot_items.length + " items");}


					var rndItem = Math.ceil(Math.random() * rot_items.length) - 1;
					var container_cycle_elements = $('<div/>')
														.addClass('container_cycle_elements')
														.css('overflow','hidden')
														.append(rot_items)
														.WG_SizeElemAsElem(html_elem);

					switch(options.type)
					{
						case 'cycle':
							$(html_elem).html(container_cycle_elements.cycle({
																			    fx: 		options.cycle_fx,
																			    speed:     	options.cycle_speed,
																			    timeout: 	options.cycle_timeout,
																			    random:  	options.cycle_random
																			}));
							break;
						case 'random':
							$(html_elem).html(rot_items[rndItem]);
							break;

					}
					options.cb.call();
				}


            });
		}
    });
})(jQuery);


(function($) {

   $.fn.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
      return this;
   }
})(jQuery);

jQuery.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
};


(function($) {
   $.fn.WG_SizeElemAsElem = function(elem2imitate) {
		return this.each(function() {
			$(this).css({
						'height': $(elem2imitate).height() + 'px',
						'width': $(elem2imitate).width() + 'px'
					})
		});
   }
})(jQuery);

(function($) {
   $.fn.WG_CenterText = function() {
		return this.each(function() {
			var pos_top_txt = ($(elem).height() - $(this).height())/2;
			$(this).css({
						'text-align': 'center',
						'top': pos_top_txt + 'px',
						'position': 'absolute',
						'left': '0px',
						'width': $(this).width() + 'px'
					})
		});
   }
})(jQuery);


/*
 * $ WG Ajax plug-in 1.0
 * Copyright (c) 2008 Roberto Lee
 */
 /*
 * $ plug-in WG Ajax  2.0
 *
 * Copyright (c) 2008 Roberto Lee (webgenerator.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2009-04-01
 * Rev: 1
 */

(function($){
     $.fn.extend({
         WG_Ajax: function(options) {
	        var defaults = {
				path_loading_image: '/ajax_loading.gif',
				url: '',
				traverse_partial: '',
				message_on_error:null,
				old_content_on_error: false,
				loadingpaddingtop: '15',
				loadingpaddingbottom: '0',
				async: false,
				cache: false,
				cb: function(){}
	        };
	        var options = $.extend(defaults, options);

            return $(this).each(function(idx) {// Don't break the chain
            	html_elem = this;
				var oldContent = $(this).html();
				var LoadingImageDiv = $('<div/>')	.addClass('ajax_container')
													.css({
														'color': 'red',  'font-size': '12px', 'text-align': 'center',
														'width': '100%', 'margin': '0px',
														'padding': options.loadingpaddingtop+'px 0px '+options.loadingpaddingbottom+'px 0px'
													})
													.append($('<img/>').attr({
																			'src':	options.path_loading_image,
																			'alt':  'loading...'
																		})
												);
				$(html_elem).html(LoadingImageDiv);
				try {
							$.ajax({
									async: options.async,
									cache: options.cache,
									url: options.url,
									beforeSend: function(){
									},
									success: function(data){
											var ajax_result = $('<div/>').append($.trim(data));
											if(ajax_result.find(options.traverse_partial).is('*'))
											{
												ajax_result = ajax_result.find(options.traverse_partial);
											}
											$(html_elem).html(ajax_result.html());
									},
									error: function(xhr, ajaxOptions, thrownError){
										var errMsg =  $.trim(options.message_on_error) != "" ? options.message_on_error : xhr.statusText + " ("+xhr.status+")";
										$(html_elem).html(options.old_content_on_error == false ? $(LoadingImageDiv).html(errMsg) : oldContent);

									},
									complete: function(){
										options.cb.call();
									}
							})
				}
				catch (e) {
					$(html_elem).html($(LoadingImageDiv).html(e.message));//.log(e.message); //e.name + " " +   //Catch cross domain error
				}
            });
		}
    });
})(jQuery);


