/**
 * Core Design Flip Wall plugin for Joomla! 1.5
 * @author		Daniel Rataj, <info@greatjoomla.com>
 * @package		Joomla
 * @subpackage	Content
 * @category   	Plugin
 * @version		1.0.0 Experimental
 * @copyright	Copyright (C) 2007 - 2010 Great Joomla!, http://www.greatjoomla.com
 * @license		http://www.gnu.org/copyleft/gpl.html GNU/GPL 3
 * 
 * This file is part of Great Joomla! extension.   
 * This extension is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This extension is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

if (typeof jQuery === 'function') {
	(function($) {
		
		$.fn.cdflipwall = function(options) {

			// set defaults
			var defaults = {
					direction : 'rl',
					speed : 500,
					width : 0,
					height : 0
			},
			opts = $.extend(defaults, options);
			
			return this.each(function() {
				var $this = $(this);
				$('.wall', $this).each(function() {
					
					// css width and height overrides
					if (opts.width !== '0') $('.wall_page1, .wall_page2', $(this)).css('width', opts.width);
					if (opts.height!== '0') $('.wall_page1, .wall_page2', $(this)).css('height', opts.height);
					
					$('.wall_page1', $(this)).show().click(function() {
						if ($(this).data('flipped') === true) {
							// already flipped
							$(this).data('flipped', false);
							$(this).revertFlip();
						} else {
							$(this).data('flipped', true);
							$(this).flip({
								direction : opts.direction,
								dontChangeColor : true,
								speed : opts.speed,
								content : $('.wall_page2', $(this).closest('.wall')),
								onEnd: function(){
									// make links clickable
									$('a', $this).click(function(e) {
										window.open($(this).attr('href'));
										return false;
									});
								}
							});
						}
					}).hover(
						function() {
							$(this).addClass('wall_hover');
						},
						function() {
							$(this).removeClass('wall_hover');
						}
					);
				});
				
			});
			
		};
		
	})(jQuery);
}
