// accordion.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// 
// Accordion is freely distributable under the terms of an MIT-style license.
//
// I don't care what you think about the file size...
//   Be a pro: 
//	    http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
//      http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
//

/*-----------------------------------------------------------------------------------------------*/

if (typeof Effect == 'undefined') 
	throw("accordion.js requires including script.aculo.us' effects.js library!");

var accordion = Class.create();
accordion.prototype = {

	//
	//  Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	
	//  
	//  Initialize the accordions
	//
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false;
	  }
	  
		this.options = Object.extend({
			resizeSpeed : 5,
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				height : 370,
				width : null
			},
			direction : 'vertical',
			onEvent : 'click'
		}, options || {});
		
		this.duration = ((11-this.options.resizeSpeed)*0.15);

		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {
			  accordion.onclick = function() {return false;};
			}
			
			if (this.options.direction == 'horizontal') {
				var options = $H({width: '0px'});
			} else {
				var options = $H({height: '0px'});			
			}
			options.merge({display: 'none'});			
			
			this.currentAccordion = $(accordion.next(0)).setStyle(options);			
		}.bind(this));
	},
	
	//
	//  Activate an accordion
	//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}
		
		this.effects = [];
	
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});		
		
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

		if (this.options.direction == 'horizontal') {
			this.scaling = $H({
				scaleX: true,
				scaleY: false
			});
		} else {
			this.scaling = $H({
				scaleX: false,
				scaleY: true
			});			
		}
			
		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate();
		} else {
		  this._handleAccordion();
		}
},
initialactivate: function(accordion) {
        if (this.animating) {
            return false;
        }

        this.effects = [];

        this.currentAccordion = $(accordion.next(0));
        this.currentAccordion.setStyle({
            display: 'block'
        });

        this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

        if (this.options.direction == 'horizontal') {
            this.scaling = $H({
                scaleX: true,
                scaleY: false
            });
        } else {
            this.scaling = $H({
                scaleX: false,
                scaleY: true
            });
        }

        if (this.currentAccordion == this.showAccordion) {
            this.deactivate();
        } else {
            this._defaulthandleAccordion();
        }
    },
    
       _defaulthandleAccordion: function() {
	        var options = $H({
	            sync: true,
	            scaleFrom: 0,
	            scaleContent: false,
	            transition: Effect.Transitions.full,
	            scaleMode: {
	                originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
	                originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
	            }
	        });


	        options.merge(this.scaling);

	        this.effects.push(
			    new Effect.Scale(this.currentAccordion, 100, options)
		    );



	        if (this.showAccordion) {
	            this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);

	            options = $H({
	                sync: true,
	                scaleContent: false,
	                transition: Effect.Transitions.full         
	                
	            });
	            options.merge(this.scaling);

	            this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options)
			);
	        }

	        new Effect.Parallel(this.effects, {
	            duration: 0,
	            queue: {
	                position: 'end',
	                scope: 'accordionAnimation'
	            },
	            beforeStart: function() {
	                this.animating = true;
	            } .bind(this),
	            afterFinish: function() {
	                if (this.showAccordion) {
	                    this.showAccordion.setStyle({
	                        display: 'none'
	                    });
	                }
	                $(this.currentAccordion).setStyle({
	                    height: '370' // set the height of the image
	                });
	                this.showAccordion = this.currentAccordion;
	                this.animating = false;
	            } .bind(this)
	        });
	    },
	// 
	// Deactivate an active accordion
	//
	deactivate : function() {
		var options = $H({
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
          height: '370', //So that the height won't change on toggle.
					display: 'none'
				});				
				this.showAccordion = null;
				this.animating = false;
			}.bind(this)
		});    
    options.merge(this.scaling);
   	    
		  if (this.showAccordion) {  
             this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
        
		     new Effect.Scale(this.showAccordion, 0, options);
		    }
	    },


	    //
	    // Handle the open/close actions of the accordion
	    //
	    _handleAccordion: function() {
	        var options = $H({
	            sync: true,
	            scaleFrom: 0,
	            scaleContent: false,
	            transition: Effect.Transitions.sinoidal,
	            scaleMode: {
	                originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
	                originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
	            }
	        });


	        options.merge(this.scaling);

	        this.effects.push(
			    new Effect.Scale(this.currentAccordion, 100, options)
		    );



	        if (this.showAccordion) {
	            this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);

	            options = $H({
	                sync: true,
	                scaleContent: false,
	                transition: Effect.Transitions.sinoidal           
	                
	            });
	            options.merge(this.scaling);

	            this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options)
			);
	        }

	        new Effect.Parallel(this.effects, {
	            duration: this.duration,
	            queue: {
	                position: 'end',
	                scope: 'accordionAnimation'
	            },
	            beforeStart: function() {
	                this.animating = true;
	            } .bind(this),
	            afterFinish: function() {
	                if (this.showAccordion) {
	                    this.showAccordion.setStyle({
	                        display: 'none'
	                    });
	                }
	                $(this.currentAccordion).setStyle({
	                    height: '370' // set the height of the image
	                });
	                this.showAccordion = this.currentAccordion;
	                this.animating = false;
	            } .bind(this)
	        });
	    }
	   
	    
	   
}
/* added */
function ShowRelevantLogos(evt) {
    var target = Event.element(evt);
    var id = target.className;
    var index = id.charAt(id.indexOf("menu-") + 6);
    CallSubFunction(index);
}

function CallSubLogos(index) {
    var target = $$('#horizontal_container .horizontal_accordion_toggle')[index];
    var id = target.className;
    var i = id.charAt(id.indexOf("menu-") + 6);  
    CallSubFunction(i);
}
function CallSubFunction(index) {
    ($$('.subsidiaries .pricebreaker')[0]).className = 'pricebreaker';
    ($$('.subsidiaries .collyers')[0]).className = 'collyers';
    ($$('.subsidiaries .princess-cruises')[0]).className = 'princess-cruises';
    ($$('.subsidiaries .cunard')[0]).className = 'cunard';
    ($$('.subsidiaries .chukchak')[0]).className = 'chukchak';
  
    if (index == 0) {
        ($$('.subsidiaries .pricebreaker')[0]).addClassName('pricebreaker-a');
        ($$('.subsidiaries .collyers')[0]).addClassName('collyers-a');
        ($$('.subsidiaries .princess-cruises')[0]).addClassName('princess-cruises-a');
        ($$('.subsidiaries .chukchak')[0]).addClassName('chukchak-a');
        ($$('.subsidiaries .cunard')[0]).addClassName('cunard-a');
    }
    else if (index == 1) {
        ($$('.subsidiaries .pricebreaker')[0]).addClassName('pricebreaker-a');
       // ($$('.subsidiaries .collyers')[0]).addClassName('collyers-a');
    } else if (index == 2) {
        ($$('.subsidiaries .princess-cruises')[0]).addClassName('princess-cruises-a');
        ($$('.subsidiaries .cunard')[0]).addClassName('cunard-a');
    } else if (index == 3) {
        ($$('.subsidiaries .chukchak')[0]).addClassName('chukchak-a');
    } else if (index == 4) {
        ($$('.subsidiaries .pricebreaker')[0]).addClassName('pricebreaker-a');
    } else if (index == 5) {
        ($$('.subsidiaries .pricebreaker')[0]).addClassName('pricebreaker-a');
    } else if (index == 6) {
        ($$('.subsidiaries .pricebreaker')[0]).addClassName('pricebreaker-a');
		}
}
/* added */

	