/* ------------------------------------------------------*
 *    Artists At This Event                              *
 * ------------------------------------------------------*/
LIVENATION.page.artists_at_this_event = function(item_data) {
    var section_id = item_data.section_id;
    var artists = item_data.artists.artist;
    var friendly_urls = item_data.friendly_urls;
	var width = $(section_id).getWidth();
	var coords = $(section_id).getCoordinates();
    var section_header = item_data.section_header;
    var see_all_concert_dates = item_data.see_all_concert_dates;
    var show_less_label = item_data.show_less_label;

	var show_all_click = function(_artists, _friendly_urls, coords, _width, _section_header, _see_all_concert_dates, _show_less_label) {
		return function() {
			popAllArtists(_artists, _friendly_urls, coords, _width, _section_header, _see_all_concert_dates, _show_less_label);
			return false;
		}
	}

	if ($(section_id + '_show_all') != null)	
	    $(section_id + '_show_all').addEvent('click', show_all_click(artists, friendly_urls, coords, width, section_header, see_all_concert_dates, show_less_label));  		    

    function popAllArtists(artists, friendly_urls, coords, width, section_header, see_all_concert_dates, show_less_label) {

        var popup = $(section_id + '_popup');
        // if the popup div does not yet exist...
        if (!$defined(popup)) {
            // ...create it.
    		popup = new Element('div', { 'id' : section_id + '_popup'});

    		var h2 = new Element('h2').appendText(section_header);
    		$(popup).appendChild(h2);

       		var ul = new Element('ul');
            var li, li_span, li_a;
            for (i=0; i < artists.length; i++) {
                // if the artist has a name...
				if ($defined(artists[i].name)) {
                    // ...create the row for the artist.
                    li = new Element('li');
    				if (friendly_urls[i] != null) {
                        li_a = new Element('a', {'href' : decodeURI(friendly_urls[i])}).appendText(artists[i].name);
                    } else {
                        li_a = new Element('a', {'href' : '/adp/artistId/' + artists[i]['@id']}).appendText(artists[i].name);
                    }
                    $(li).appendChild(li_a);
                    $(ul).appendChild(li);
				}
            }
            $(popup).appendChild(ul);

    		var p = new Element('p');
    		var p_a = new Element('a', {
				'id' : 'close_' + section_id + '_popup',
				'href' : '/#'
			}).appendText(show_less_label);
            

    		$(p_a).addEvent('click', function(event) {
                $(popup).setStyle('display','none');
            	$(section_id).removeClass("hidden");
                return false;
    		});
            $(p).appendChild(p_a);
            $(popup).appendChild(p);

    		$('lower_right_column').appendChild(popup);
    		$(popup).setStyle('width', width + 20); // add width of scroll bar to 'width'
    		$(popup).setStyle('left', coords.left - 10);
    		$(popup).setStyle('top', coords.top - 2);
        } // end if 

        // hide the non-popup
        $(section_id).addClass("hidden");
        // show the popup
        $(popup).setStyle('display','block');

        return false;
    } // end popAllArtists()

} // end LIVENATION.page.artists_at_this_event

// Omniture link tracking for add to outlook
LIVENATION.global.track_ical = function() {
    var s=s_gi(s_account);
    s.linkTrackVars='events';
    s.linkTrackEvents='event12';
    s.events='event12';
    s.tl(this,'o','iCal File Downloads');       
}

$$('a[rel=outlook_link]').addEvent('click', function(e) {
    LIVENATION.global.track_ical();
}.bind(this));

// if xsl set up the registry...
if (LIVENATION.registry.page.artists_at_this_event) {
    window.addEvent('domready', function() {
        if (LIVENATION.instances.page.artists_at_this_event !== 'object') {
            LIVENATION.instances.page.artists_at_this_event = new Array();
        }
        for (i = 0; i < LIVENATION.registry.page.artists_at_this_event.length; i++) {
            LIVENATION.instances.page.artists_at_this_event.push( 
                new LIVENATION.page.artists_at_this_event(LIVENATION.registry.page.artists_at_this_event[i])
            );
        }
    })
}//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

var Asset=new Hash({javascript:function(F,D){D=$extend({onload:$empty,document:document,check:$lambda(true)},D);var B=new Element("script",{src:F,type:"text/javascript"});
var E=D.onload.bind(B),A=D.check,G=D.document;delete D.onload;delete D.check;delete D.document;B.addEvents({load:E,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){E();
}}}).setProperties(D);if(Browser.Engine.webkit419){var C=(function(){if(!$try(A)){return ;}$clear(C);E();}).periodical(50);}return B.inject(G.head);},css:function(B,A){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:B},A)).inject(document.head);
},image:function(C,B){B=$merge({onload:$empty,onabort:$empty,onerror:$empty},B);var D=new Image();var A=$(D)||new Element("img");["load","abort","error"].each(function(E){var F="on"+E;
var G=B[F];delete B[F];D[F]=function(){if(!D){return ;}if(!A.parentNode){A.width=D.width;A.height=D.height;}D=D.onload=D.onabort=D.onerror=null;G.delay(1,A,A);
A.fireEvent(E,A,1);};});D.src=A.src=C;if(D&&D.complete){D.onload.delay(1);}return A.setProperties(B);},images:function(D,C){C=$merge({onComplete:$empty,onProgress:$empty},C);
if(!D.push){D=[D];}var A=[];var B=0;D.each(function(F){var E=new Asset.image(F,{onload:function(){C.onProgress.call(this,B,D.indexOf(F));B++;if(B==D.length){C.onComplete();
}}});A.push(E);});return new Elements(A);}});LIVENATION.module.video = function(item_data) {
    var module_id = item_data.module_id;

//	if (item_data.browser == 'IE 6.0') {
    	var video_player = new Swiff(item_data.static_server_path + 'modules/photo_video/default/jw_player/player.swf',
        {
            id: 'video_player',
            width: item_data.width,
            height: item_data.height,
            container: item_data.module_id,
            params: {
                wmode: 'opaque',
                bgcolor: '#fff',
								allowfullscreen: 'true',
								allowscriptaccess: 'always'
            },
            vars: {
                image: item_data.image,
                file: item_data.file,
                skin: item_data.skin, 
                fullscreen: true,
								controlbar: 'over'
            }
        });
//	}

}

window.addEvent('domready', function() {
        if (LIVENATION.instances.video !== 'object') {
            LIVENATION.instances.video = new Array();
        }

				if ($type(LIVENATION.registry.video) == 'array') {
					for (i = 0; i < LIVENATION.registry.video.length; i++) {
						LIVENATION.instances.video.push(new LIVENATION.module.video(LIVENATION.registry.video[i]));
					}
				}

})
LIVENATION.module.buy_tickets = function(item_data) {
    var module_id = item_data.module_id;
    var remind_me = item_data.remind_me;
    var remind_me_popup = item_data.remind_me_popup;
    var thank_popup = item_data.thank_popup;
    var thank_popup_closer = item_data.thank_popup_closer;
    var blank_sender_email = item_data.blank_sender_email;
    var closer = item_data.closer;
    var error = item_data.error;
    var error_msg = item_data.error_msg;
    var invalid_email_msg = item_data.invalid_email_msg;
    var error_duplicate_msg = item_data.error_duplicate_msg;
    var reminder_form = item_data.reminder_form;
    var coords = 0;

//    this.omni_data = item_data.omni_data;
//    this.omni_reminder = item_data.reminder_omniture;

    /* function to report to omniture for public onsale reminder functionality */
    this.reminder_to_omniture = function() {
        this.ln_omni = new ln_omniture(item_data.reminder_omniture);
        this.ln_omni.send_to_omniture_tl();
    }

    /* function to report to omniture on buy ticket button click */
    this.send_to_omniture = function(str_rel, linkElement) {
		this.omni_data.products += ';;;;evar38=' + str_rel;
		this.omni_data.eVar38 = str_rel;
        this.ln_omni = new ln_omniture(this.omni_data);
        this.ln_omni.send_to_omniture_tl(linkElement);
    }  

    if ($(item_data.remind_me) != null) {
        $(item_data.remind_me).addEvent('click', function() {   
            this.reminder_to_omniture();
            $(reminder_form).reset();
            $(remind_me_popup).setStyle('display', 'block');
            $(remind_me_popup).setStyles({
                'top': 150,
                'left' : document.window.getSize().x/2 - $(remind_me_popup).getSize().x.toInt()/2
            });
            $(error).empty();
            $$("'." + closer + "'").addEvent('click', function() {
                $(remind_me_popup).setStyle('display', 'none');
            }.bind(this));
            $$('img.' + thank_popup_closer).addEvent('click', function() {
                $(thank_popup).setStyle('display', 'none');
            }.bind(this));
        }.bind(this));
        $(reminder_form).addEvent('submit', function(e) {
            if ($('email').value.length == 0) {
                $(error).set('html', blank_sender_email);
                return false;
            }
            e.stop();
            $(error).empty();
            $(reminder_form).set('send', {
                url: '/zetaOnSaleAlert',
                method: 'post',
                onSuccess: function(_response) {
                    response = JSON.decode(_response);
                    if ($defined(response.error)) {
                        if (response.error == 'duplicate'){
                            $(error).set('html', error_duplicate_msg);
                        }else if (response.error == 'invalid_email_address'){
                            $(error).set('html', invalid_email_msg);
                        }else{

                            $(error).set('html', error_msg);
                        }
                    } else if (response.success == 'ok') {
                        $(remind_me_popup).setStyle('display', 'none');
                        $(thank_popup).setStyle('display', 'block');
                        $(thank_popup).setStyles({
                            'top': 150,
                            'left' : document.window.getSize().x/2 - $(thank_popup).getSize().x.toInt()/2,
                            'z-index' : 60
                        });
                    }
                }
            });
            $(reminder_form).send();
        }.bind(this));
    }

	$$('a.ticket_link[rel=ticket_link:standard_onsale]').addEvent('click', function(e) {
        this.omni_data = item_data.omni_data;
		//e.stop();
		e.preventDefault();
		e.stopPropagation();
		var linkElement = $$('a.ticket_link[rel=ticket_link:standard_onsale]');

		var _id = '';	

		if ($(e.target).get('tag') == 'a') { 
			_id = $(e.target).rel;
			_target = $(e.target).target;
			_href = $(e.target).href;
		}
		else {
			_id = $(e.target).getParent('a').rel;
			_target = $(e.target).getParent('a').target;
			_href = $(e.target).getParent('a').href;			
		}

		_id = (_id.split(':')[1]).toLowerCase(); 
		
		if (_target != "") {
			window.open(_href);			
		}
		else {
			(function(){ window.location.href = _href; }).delay(500);
		}

        this.omni_data = item_data.omni_data;
		this.send_to_omniture(_id, linkElement);
	}.bind(this));

    if($('presale_info')) {
        $('presale_info').addEvent('mouseenter', function(e){
            var tooltip = new Element('div', {
                'id' : 'presale_info_tooltip',
                'class' : 'presale_info_tooltip',
                'style' : 'display: block; z-index: 99;'
            });
            
            var presale_hover_header = new Element('h4');
            presale_hover_header.appendText('Presale Info');
            
            var presale_list = new Element('ul');
    
            for (i=0; i < item_data.presale_tickets.length; i++) {
                if(item_data.presale_tickets[i] != null) {
                    if(i == item_data.presale_tickets.length - 1) {
                        presale_list_li = new Element('li', {
                            'style' : 'border-bottom: none; padding: .5em 0;'
                        });
                    } else {
                        presale_list_li = new Element('li', {
                            'style' : 'border-bottom: .1em dotted #ccc; padding: .5em 0;'
                        });
                    }
                    list_li_p1 = new Element('p', {
                        'class' : 'ticket_description'
                    });
                    list_li_p1.appendText(item_data.presale_tickets[i]);
                    list_li_p2 = new Element('p');
                    list_li_p2.appendText(item_data.presale_tickets_info[i]);
    
                    $(presale_list_li).appendChild(list_li_p1);
                    $(presale_list_li).appendChild(list_li_p2);
                    $(presale_list).appendChild(presale_list_li);
                }
            }
            $(tooltip).appendChild(presale_hover_header);
            $(tooltip).appendChild(presale_list);
            tooltip.inject($(module_id), 'after');
        });
        $('presale_info').addEvent('mouseleave', function(e){
            if ($defined($('presale_info_tooltip'))) $('presale_info_tooltip').setStyle('display', 'none');
        });
    }

    window.addEvent("domready", function(){
        /* taken from foobarcms.com */
        /* preload image(s) */
        new Asset.images([item_data.buy_button_path,
                          item_data.hover_buy_button_path]);
        /* for multiple images: 
            new Asset.images(['/images/image1.png', '/images/image2.jpg']); 
        */
        if($('buy_tickets_button')) {
            // mouseover
            $('buy_tickets_button').addEvent('mouseover', function() { 
                $('buy_tickets_button').setProperty('src', item_data.hover_buy_button_path);
        });
            // mouseout
            $('buy_tickets_button').addEvent('mouseout', function() { 
                $('buy_tickets_button').setProperty('src', item_data.buy_button_path);
            });
        };
    });
} // end LIVENATION.module.buy_tickets

// if xsl set up the registry...
if (LIVENATION.registry.buy_tickets) {
    window.addEvent('domready', function() {
        if (LIVENATION.instances.buy_tickets !== 'object') {
            LIVENATION.instances.buy_tickets = new Array();
        }

        for (i = 0; i < LIVENATION.registry.buy_tickets.length; i++) {
            LIVENATION.instances.buy_tickets.push(
                new LIVENATION.module.buy_tickets(LIVENATION.registry.buy_tickets[i])
            );
        }
    })
}

LIVENATION.module.additional_tickets = function(item_data) {
    var module_id = item_data.module_id;
    var coords = 0;

    this.omni_data = item_data.omni_data;

    this.send_to_omniture = function(str_rel, linkElement) {
		//console.log(str_rel);
		this.omni_data.products += ';;;;evar38=' + str_rel;
		this.omni_data.eVar38 = str_rel;
        this.ln_omni = new ln_omniture(this.omni_data);
        this.ln_omni.send_to_omniture_tl(linkElement);
    }  

	$$('a.ticket_link[rel!=ticket_link:standard_onsale]').addEvent('click', function(e) {
		//e.stop();
		e.preventDefault();
		e.stopPropagation();
		var linkElement = $$('a.ticket_link[rel!=ticket_link:standard_onsale]');

		var _id = '';	

		if ($(e.target).get('tag') == 'a') { 
			_id = $(e.target).rel;
			_target = $(e.target).target;
			_href = $(e.target).href;
		}
		else {
			_id = $(e.target).getParent('a').rel;
			_target = $(e.target).getParent('a').target;
			_href = $(e.target).getParent('a').href;			
		}

		_id = (_id.split(':')[1]).toLowerCase(); 
		
		if (_target != "") {
			window.open(_href);			
		}
		else {
			(function(){ window.location.href = _href; }).delay(500);
		}

		this.send_to_omniture(_id, linkElement);
	}.bind(this));

    $$('div#' + module_id + '_more_content ul' + ' li').each(function(li) {
        li.addEvents({
            'mouseenter': function (e) {
                 e.stop();
                 showTooltip(this);
             },
             'mouseleave': function (e) {
                 e.stop();
                 hideTooltip();
             }
        });
    });

    function showTooltip(li) {
        var left = li.getCoordinates().left;
        var top = li.getCoordinates().top;

        var popup = $(module_id + '_popup');
        if (!$defined(popup)) {
            popup = new Element('div', {
                'id' : module_id + '_popup',
                'class' : 'buy_tickets_popup'
            });
        } else {
            $(popup).empty();
        }

        if (item_data.ticket_descriptions[(li.id).split(':')[1]] != null) {
            var p = new Element('p').appendText(item_data.ticket_descriptions[(li.id).split(':')[1]]);
            p.inject(popup);

            $(popup).inject($(module_id + '_more'));
            $(popup).addClass('tooltip');
            $(popup).setStyle('display', 'block');
            $(popup).setStyle('left', left-$(popup).getCoordinates().width-15);    
            $(popup).setStyle('top', top-$(popup).getCoordinates().height/2+15);

        }
    } // end popTooltip()

    function hideTooltip() {
        if ($defined($(module_id + '_popup'))) $(module_id + '_popup').setStyle('display', 'none');
    } // end hideTooltip()

} // end LIVENATION.module.additional_tickets

// if xsl set up the registry...
if (LIVENATION.registry.additional_tickets) {
    window.addEvent('domready', function() {
        if (LIVENATION.instances.additional_tickets !== 'object') {
            LIVENATION.instances.additional_tickets = new Array();
        }

        for (i = 0; i < LIVENATION.registry.additional_tickets.length; i++) {
            LIVENATION.instances.additional_tickets.push(
                new LIVENATION.module.additional_tickets(LIVENATION.registry.additional_tickets[i])
            );
        }
    })
}

LIVENATION.module.recently_reviewed = function(item_data) { 
    LIVENATION.instances.omniture.send(item_data.omni_data);
    /**
     *  Begin code for click tracking of Post a Review button. */ 
    $('post_review').addEvent('click',
        function(e){
            e.stopPropagation();
            LIVENATION.instances.omniture.send({prop3:'Step 1 - click Post a Review button'}, this, 'Post a Review Button');
        }
    );
}

// if xsl set up the registry...
if (LIVENATION.registry.recently_reviewed) {
    window.addEvent('domready', function() {
        if (LIVENATION.instances.recently_reviewed !== 'object') {
            LIVENATION.instances.recently_reviewed = new Array();
        }

        for (i = 0; i < LIVENATION.registry.recently_reviewed.length; i++) {
            LIVENATION.instances.recently_reviewed.push(
                new LIVENATION.module.recently_reviewed(LIVENATION.registry.recently_reviewed[i])
            );
        }
    })
}
LIVENATION.module.tabs = new Class({
    initialize: function(item){
		this.module_container = item.module_id;	
		this.no_reload_tabs = item.no_reload_tabs;
		
		this.attach_tab_handler();	
	},
	attach_tab_handler: function() {
		this.no_reload_tabs.each(function(no_reload_tab, index) {
			$(no_reload_tab['tab']).addEvent('click', function(e) {
				//console.log("url: " + no_reload_tab['url']);
                /* shows the waiter */
				$$('div[class^=module.tabs] div.content').wait();
                e.preventDefault();
                var self = this;
                var _html_request = new Request({
                    url : no_reload_tab['url'],
                    evalScripts: true,
                    onRequest: function() {
                        this.set_active_tab(no_reload_tab['tab']);
                		//console.log('need to set the active tab');
                    }.bind(this),
                    onSuccess: function(html) {
                        //$$('div[class^=module.tabs] div.content').setStyle('height', 100);                    	
                		$$('div[class^=module.tabs] div.content').set('html', html);
                        /* removes the waiter */                    	
                		$$('div[class^=module.tabs] div.content').release();
                    }.bind(this)
                }).get();             
			}.bind(this));
		}.bind(this));			
	},
    set_active_tab: function(tab) {
		$$('ul.tabs li').removeClass('active');
		$$('ul.tabs li a').removeClass('active');
		$(tab).getParent().addClass('active');
		$(tab).addClass('active');
    }	
});

window.addEvent('domready', function(){
    if (LIVENATION.instances.tabs !== 'object') {
        LIVENATION.instances.tabs = []
    }
    if ($defined(LIVENATION.registry.tabs)) {
        LIVENATION.registry.tabs.each(
            function(item){
                LIVENATION.instances.tabs.push(
                    new LIVENATION.module.tabs(item)
                )
            }
        )
    }
});

/*
Script: Drag.js
    The base Drag Class. Can be used to drag and resize Elements using mouse events.

    License:
        MIT-style license.

    Authors:
        Valerio Proietti
        Tom Occhinno
        Jan Kassens
*/

var Drag = new Class({

    Implements: [Events, Options],

    options: {/*
        onBeforeStart: $empty(thisElement),
        onStart: $empty(thisElement, event),
        onSnap: $empty(thisElement)
        onDrag: $empty(thisElement, event),
        onCancel: $empty(thisElement),
        onComplete: $empty(thisElement, event),*/
        snap: 6,
        unit: 'px',
        grid: false,
        style: true,
        limit: false,
        handle: false,
        invert: false,
        preventDefault: false,
        modifiers: {x: 'left', y: 'top'}
    },

    initialize: function(){
        var params = Array.link(arguments, {'options': Object.type, 'element': $defined});
        this.element = $(params.element);
        this.document = this.element.getDocument();
        this.setOptions(params.options || {});
        var htype = $type(this.options.handle);
        this.handles = ((htype == 'array' || htype == 'collection') ? $$(this.options.handle) : $(this.options.handle)) || this.element;
        this.mouse = {'now': {}, 'pos': {}};
        this.value = {'start': {}, 'now': {}};

        this.selection = (Browser.Engine.trident) ? 'selectstart' : 'mousedown';

        this.bound = {
            start: this.start.bind(this),
            check: this.check.bind(this),
            drag: this.drag.bind(this),
            stop: this.stop.bind(this),
            cancel: this.cancel.bind(this),
            eventStop: $lambda(false)
        };
        this.attach();
    },

    attach: function(){
        this.handles.addEvent('mousedown', this.bound.start);
        return this;
    },

    detach: function(){
        this.handles.removeEvent('mousedown', this.bound.start);
        return this;
    },

    start: function(event){
        if (this.options.preventDefault) event.preventDefault();
        this.mouse.start = event.page;
        this.fireEvent('beforeStart', this.element);
        var limit = this.options.limit;
        this.limit = {x: [], y: []};
        for (var z in this.options.modifiers){
            if (!this.options.modifiers[z]) continue;
            if (this.options.style) this.value.now[z] = this.element.getStyle(this.options.modifiers[z]).toInt();
            else this.value.now[z] = this.element[this.options.modifiers[z]];
            if (this.options.invert) this.value.now[z] *= -1;
            this.mouse.pos[z] = event.page[z] - this.value.now[z];
            if (limit && limit[z]){
                for (var i = 2; i--; i){
                    if ($chk(limit[z][i])) this.limit[z][i] = $lambda(limit[z][i])();
                }
            }
        }
        if ($type(this.options.grid) == 'number') this.options.grid = {x: this.options.grid, y: this.options.grid};
        this.document.addEvents({mousemove: this.bound.check, mouseup: this.bound.cancel});
        this.document.addEvent(this.selection, this.bound.eventStop);
    },

    check: function(event){
        if (this.options.preventDefault) event.preventDefault();
        var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2)));
        if (distance > this.options.snap){
            this.cancel();
            this.document.addEvents({
                mousemove: this.bound.drag,
                mouseup: this.bound.stop
            });
            this.fireEvent('start', [this.element, event]).fireEvent('snap', this.element);
        }
    },

    drag: function(event){
        if (this.options.preventDefault) event.preventDefault();
        this.mouse.now = event.page;
        for (var z in this.options.modifiers){
            if (!this.options.modifiers[z]) continue;
            this.value.now[z] = this.mouse.now[z] - this.mouse.pos[z];
            if (this.options.invert) this.value.now[z] *= -1;
            if (this.options.limit && this.limit[z]){
                if ($chk(this.limit[z][1]) && (this.value.now[z] > this.limit[z][1])){
                    this.value.now[z] = this.limit[z][1];
                } else if ($chk(this.limit[z][0]) && (this.value.now[z] < this.limit[z][0])){
                    this.value.now[z] = this.limit[z][0];
                }
            }
            if (this.options.grid[z]) this.value.now[z] -= ((this.value.now[z] - this.limit[z][0]) % this.options.grid[z]);
            if (this.options.style) this.element.setStyle(this.options.modifiers[z], this.value.now[z] + this.options.unit);
            else this.element[this.options.modifiers[z]] = this.value.now[z];
        }
        this.fireEvent('drag', [this.element, event]);
    },

    cancel: function(event){
        this.document.removeEvent('mousemove', this.bound.check);
        this.document.removeEvent('mouseup', this.bound.cancel);
        if (event){
            this.document.removeEvent(this.selection, this.bound.eventStop);
            this.fireEvent('cancel', this.element);
        }
    },

    stop: function(event){
        this.document.removeEvent(this.selection, this.bound.eventStop);
        this.document.removeEvent('mousemove', this.bound.drag);
        this.document.removeEvent('mouseup', this.bound.stop);
        if (event) this.fireEvent('complete', [this.element, event]);
    }

});

Element.implement({

    makeResizable: function(options){
        var drag = new Drag(this, $merge({modifiers: {x: 'width', y: 'height'}}, options));
        this.store('resizer', drag);
        return drag.addEvent('drag', function(){
            this.fireEvent('resize', drag);
        }.bind(this));
    }

});
/*
Script: Drag.Move.js
    A Drag extension that provides support for the constraining of draggables to containers and droppables.

    License:
        MIT-style license.

    Authors:
        Valerio Proietti
        Tom Occhinno
        Jan Kassens*/

Drag.Move = new Class({

    Extends: Drag,

    options: {/*
        onEnter: $empty(thisElement, overed),
        onLeave: $empty(thisElement, overed),
        onDrop: $empty(thisElement, overed, event),*/
        droppables: [],
        container: false,
        precalculate: false,
        includeMargins: true,
        checkDroppables: true
    },

    initialize: function(element, options){
        this.parent(element, options);
        this.droppables = $$(this.options.droppables);
        this.container = $(this.options.container);
        if (this.container && $type(this.container) != 'element') this.container = $(this.container.getDocument().body);

        var position = this.element.getStyle('position');
        if (position=='static') position = 'absolute';
        if ([this.element.getStyle('left'), this.element.getStyle('top')].contains('auto')) this.element.position(this.element.getPosition(this.element.offsetParent));
        this.element.setStyle('position', position);

        this.addEvent('start', this.checkDroppables, true);

        this.overed = null;
    },

    start: function(event){
        if (this.container){
            var ccoo = this.container.getCoordinates(this.element.getOffsetParent()), cbs = {}, ems = {};

            ['top', 'right', 'bottom', 'left'].each(function(pad){
                cbs[pad] = this.container.getStyle('border-' + pad).toInt();
                ems[pad] = this.element.getStyle('margin-' + pad).toInt();
            }, this);

            var width = this.element.offsetWidth + ems.left + ems.right;
            var height = this.element.offsetHeight + ems.top + ems.bottom;

            if (this.options.includeMargins) {
                $each(ems, function(value, key) {
                    ems[key] = 0;
                });
            }
            if (this.container == this.element.getOffsetParent()) {
                this.options.limit = {
                    x: [0 - ems.left, ccoo.right - cbs.left - cbs.right - width + ems.right],
                    y: [0 - ems.top, ccoo.bottom - cbs.top - cbs.bottom - height + ems.bottom]
                };
            } else {
                this.options.limit = {
                    x: [ccoo.left + cbs.left - ems.left, ccoo.right - cbs.right - width + ems.right],
                    y: [ccoo.top + cbs.top - ems.top, ccoo.bottom - cbs.bottom - height + ems.bottom]
                };
            }

        }
        if (this.options.precalculate){
            this.positions = this.droppables.map(function(el) {
                return el.getCoordinates();
            });
        }
        this.parent(event);
    },

    checkAgainst: function(el, i){
        el = (this.positions) ? this.positions[i] : el.getCoordinates();
        var now = this.mouse.now;
        return (now.x > el.left && now.x < el.right && now.y < el.bottom && now.y > el.top);
    },

    checkDroppables: function(){
        var overed = this.droppables.filter(this.checkAgainst, this).getLast();
        if (this.overed != overed){
            if (this.overed) this.fireEvent('leave', [this.element, this.overed]);
            if (overed) this.fireEvent('enter', [this.element, overed]);
            this.overed = overed;
        }
    },

    drag: function(event){
        this.parent(event);
        if (this.options.checkDroppables && this.droppables.length) this.checkDroppables();
    },

    stop: function(event){
        this.checkDroppables();
        this.fireEvent('drop', [this.element, this.overed, event]);
        this.overed = null;
        return this.parent(event);
    }

});

Element.implement({

    makeDraggable: function(options){
        var drag = new Drag.Move(this, options);
        this.store('dragger', drag);
        return drag;
    }

});


LIVENATION.module.rondavu = new Class({
    Implements: [Events, Options, Chain],
    options: {
    },
    initialize: function(options){
        this.setOptions(options.obj);
        this.opener = options.opener;
        this.closer = options.closer;
        this.popup = options.popup;
        this.drag = options.dragger;
        this.form_submit = options.form_submit;
        this.sender_error = options.sender_error;
        this.recipient_error = options.recipient_error;
        this.message_error = options.message_error;
        this.errors = options.errors;
        this.thank_popup = options.thank_popup;
        this.thank_popup_close = options.thank_popup_close;
        this.send_to_friend_omniture = options.send_to_friend_omniture;

        this.attach_opener();
        this.handle_form_submit();
        //this.attach_drag();

    },
    report_to_omniture: function() {
        this.ln_omni = new ln_omniture(this.send_to_friend_omniture);
        this.ln_omni.send_to_omniture_tl();
    },
    attach_drag: function() {
    	var myDrag = new Drag.Move($(this.popup), {
            handle: $(this.drag),
            container: $(window)
    	});
    },
    attach_closer: function() {
        $$("'." + this.closer + "'").addEvents({
            'click' : function() {
                $(this.popup).setStyle('display', 'none');
            }.bind(this),
            'keypress' : function() {
                $(this.popup).setStyle('display', 'none');
            }.bind(this)
        });
        $(this.popup).getElements('.error').each(function(err) {
            err.empty();
        });
        this.remove_listeners();
    },
    attach_opener: function() {
        $(this.opener).addEvent('click', function() {
            $('send_to_friend_form').reset();
            $(this.popup).setStyle('display', 'block');
            $(this.popup).setStyles({
                'top' : 100,
                'left' : document.window.getSize().x/2 - $(this.popup).getSize().x.toInt()/2,
                'z-index' : 50
            });            
            $('your_email').focus();
            $(this.popup).getElements('input[type=text], textarea').each(function(field) {
                field.value='';
            });
            this.attach_closer();
            this.report_to_omniture();
        }.bind(this));
    },
    handle_form_submit: function() {
        $$("'." + this.form_submit + "'").addEvent('click', function(e) {
            if ($('your_email').value.length == 0) {
                $(this.sender_error).set('html', this.errors.blank_sender_email);
                return false;
            }
            if ($('friend_email').value.length == 0) {
                $(this.recipient_error).set('html', this.errors.blank_recipient_email);
                return false;
            }
            if ($('message').value.length > 255) {
                $(this.message_error).set('html', this.errors.message_long);
                return false;
            }
            new Event(e).stop();
            $(this.sender_error).empty();
            $(this.recipient_error).empty();
            $(this.message_error).empty();
            $(this.popup).getElement('form').set('send', {
                url: '/zetaToFriend',
                method: 'post',
                onSuccess: function(_response) {
                    recipient_failure = 0;
                    response = new Hash(JSON.decode(_response));
                    response.each(function(value, key) {
                        if (value == 'invalid_sender') {
                            $(this.sender_error).set('html', this.errors.sender_email);
                        } else if (value.error == 'invalid_recipient') {
                            if (recipient_failure == 0) {
                                recipient_failure = 1;
                                $(this.recipient_error).set('html', this.errors.recipient_email);
                            }
                        } else if (value == 'too_many_emails') {
                            $(this.recipient_error).set('html', this.errors.too_many_emails);
                        } else if (value == 'invalid_sender_address'){
                            $(this.sender_error).set('html', this.errors.recipient_error);
                        } else if (value == 'invalid_recipient_address'){
                            $(this.recipient_error).set('html', this.errors.recipient_error);
                        } else {
                            // ok
                            $(this.popup).setStyle('display', 'none');
                            $(this.thank_popup).setStyle('display', 'block');
                            $(this.thank_popup).setStyles({
                                'left': document.window.getSize().x/2 - $(this.thank_popup).getSize().x.toInt()/2,
                                'top' : 300,
                                'z-index' : 50
                            });
                            $$("'." + this.thank_popup_close + "'").addEvent('click', function() {
                                $(this.thank_popup).setStyle('display', 'none');
                            }.bind(this));
                        }
                    }.bind(this));
                }.bind(this)
            });
            $(this.popup).getElement('form').send();
        }.bind(this));
    },
    remove_listeners: function() {
        $$("'." + this.closer + "'").removeEvent('click');
    }
})

//window.addEvent('domready', function(){
    if (LIVENATION.instances.rondavu !== 'object') {
        LIVENATION.instances.rondavu = []
    }
    if ($defined(LIVENATION.registry.rondavu)) {
        LIVENATION.registry.rondavu.each(
            function(item){
                LIVENATION.instances.rondavu.push(
                    new LIVENATION.module.rondavu(item)
                )
            }
        )
    }
//})
