/*
 * @author			Daniyal Hamid
 * @created			04-July-2010
 * @revised			N/A
 * @description		"Generic Popups" script lets you create different kinds of Popups; 
 *					such as Tooltips, Message Boxes, Alerts, Prompts tc. with support for
 *					complex structures. It comes with two classes; one to create a Popup  
 * 					and the other to assign multiple event handlers to elements, to show/hide
 *					the Popup(s).
 * 
 * @license			This JavaScript file is a commercial file, available for purchase at 
 *					http://codecanyon.net/user/daniyal/portfolio. Any illegal copying, 
 *					distribution, packaging or re-production of this script for commercial or 
 *					personal use is strictly prohibited and will be considered theft.
 *
 * @copyright		The author is the first owner of copyright and reserves all rights to
 *					all written work contained in this file. Distribution, re-production
 *					or commercial use of the written work in this file, without the author's 
 * 					signed permission, prior consent or a valid license, is strictly prohibited.
 *					The author is protected by the "Copyright, Designs and Patents Act 1988" of 
 *					the United Kingdom. Any infringement of the copyright, in or outside of the
 *					United Kingdom, may result in a lawsuit.
 */

window.addEvent('domready', function() {	
	/*
	 * Resets and repositions all elements when called.
	 */
	function reposition() {
		popup1.resetCoordinates();
		popup2.resetCoordinates();
		popup3.resetCoordinates();
		popup4.resetCoordinates();
		popup5.resetCoordinates();
		popup6.resetCoordinates();
		popup7.resetCoordinates();
		popup8.resetCoordinates();
		popup9.resetCoordinates();
		popup10.resetCoordinates();
		popup11.resetCoordinates();
		popup12.resetCoordinates();
		popup13.resetCoordinates();
		popup14_bg.resetCoordinates();
		popup14.resetCoordinates();
		popup15_tag1.resetCoordinates();
		popup15_tag2.resetCoordinates();
		popup15_tag3.resetCoordinates();
		popup15_tag4.resetCoordinates();
		popup15_tag5.resetCoordinates();
		
		
		popup1.position(popup1Pos);
		popup2.position(popup2Pos);
		popup3.position(popup3Pos);
		popup4.position(popup4Pos);
		popup5.position(popup5Pos);
		popup6.position(popup6Pos);
		popup7.position(popup7Pos);
		popup8.position(popup8Pos);
		popup9.position(popup9Pos);
		popup10.position(popup10Pos);
		popup11.position(popup11Pos);
		popup12.position(popup12Pos);
		popup13.position(popup13Pos);
		popup14.position(popup14Pos);
		popup14_bg.position(popup14_bgPos);
		popup15_tag1.position(popup15_tag1Pos);
		popup15_tag2.position(popup15_tag2Pos);
		popup15_tag3.position(popup15_tag3Pos);
		popup15_tag4.position(popup15_tag4Pos);
		popup15_tag5.position(popup15_tag5Pos);
	}
	
	window.addEvent('resize', reposition);
	
	
	/*
	 * The code below is for the examples.
	 */
	
	
	
	
	/*****
				Popup#4
	*****/
	var popup4 = new Popup('struct4', 'p', {
		showOpacity: 1.0,
		onRegionOver: function() {this.show(1);},
		onRegionOut: function() {this.hide();}
	});
	var popup4Pos = {
		relativeTo: document.id('handler4'),
		x: 'center',
		y: 'top'
	};
	
	var handler4 = new PopupHandler([popup4]);
	handler4.assign('#handler4', 'mouseenter', 'show');
	handler4.assign('#handler4', 'mouseleave', 'hide');
	
	
	
	
	// the order in which popups are stored; at 0 popup15_tag1, at 1 popup15_tag2 and so on...
	var handler14_tag = new PopupHandler([popup15_tag1, popup15_tag2, popup15_tag3, popup15_tag4, popup15_tag5]);	
	
	handler14_tag.assign('#handler15_area1', 'mouseenter', 'show', {toIndex: 0});
	handler14_tag.assign('#handler15_area1', 'mouseleave', 'hide', {toIndex: 0});
	handler14_tag.assign('#handler15_lnk1', 'mouseenter', 'show', {toIndex: 0});
	handler14_tag.assign('#handler15_lnk1', 'mouseleave', 'hide', {toIndex: 0});
	
	handler14_tag.assign('#handler15_area2', 'mouseenter', 'show', {toIndex: 1});
	handler14_tag.assign('#handler15_area2', 'mouseleave', 'hide', {toIndex: 1});
	handler14_tag.assign('#handler15_lnk2', 'mouseenter', 'show', {toIndex: 1});
	handler14_tag.assign('#handler15_lnk2', 'mouseleave', 'hide', {toIndex: 1});
	
	handler14_tag.assign('#handler15_area3', 'mouseenter', 'show', {toIndex: 2});
	handler14_tag.assign('#handler15_area3', 'mouseleave', 'hide', {toIndex: 2});
	handler14_tag.assign('#handler15_lnk3', 'mouseenter', 'show', {toIndex: 2});
	handler14_tag.assign('#handler15_lnk3', 'mouseleave', 'hide', {toIndex: 2});
	
	handler14_tag.assign('#handler15_area4', 'mouseenter', 'show', {toIndex: 3});
	handler14_tag.assign('#handler15_area4', 'mouseleave', 'hide', {toIndex: 3});
	handler14_tag.assign('#handler15_lnk4', 'mouseenter', 'show', {toIndex: 3});
	handler14_tag.assign('#handler15_lnk4', 'mouseleave', 'hide', {toIndex: 3});
	
	handler14_tag.assign('#handler15_area5', 'mouseenter', 'show', {toIndex: 4});
	handler14_tag.assign('#handler15_area5', 'mouseleave', 'hide', {toIndex: 4});
	handler14_tag.assign('#handler15_lnk5', 'mouseenter', 'show', {toIndex: 4});
	handler14_tag.assign('#handler15_lnk5', 'mouseleave', 'hide', {toIndex: 4});
	
	
	// call to position popups the first time
	reposition();
	
	/*
	 * The code below is for the examples page Menu!
	 */
	
	// BEGIN MENU
	document.getElement('#menu li:nth-child(1)').addEvent('click', function() {
		this.addClass('active');
		document.getElement('#menu li:nth-child(2)').removeClass('active');
		document.getElement('#menu li:nth-child(3)').removeClass('active');
		
		document.id('menu1').setStyle('display', 'block');
		document.id('menu2').setStyle('display', 'none');
		document.id('menu3').setStyle('display', 'none');
		
		// reposition popups
		reposition();
	});
	
	document.getElement('#menu li:nth-child(2)').addEvent('click', function() {
		this.addClass('active');
		document.getElement('#menu li:nth-child(1)').removeClass('active');
		document.getElement('#menu li:nth-child(3)').removeClass('active');
		
		document.id('menu1').setStyle('display', 'none');
		document.id('menu2').setStyle('display', 'block');
		document.id('menu3').setStyle('display', 'none');
		
		// reposition popups
		reposition();
	});
	
	document.getElement('#menu li:nth-child(3)').addEvent('click', function() {
		this.addClass('active');
		document.getElement('#menu li:nth-child(1)').removeClass('active');
		document.getElement('#menu li:nth-child(2)').removeClass('active');
		
		document.id('menu1').setStyle('display', 'none');
		document.id('menu2').setStyle('display', 'none');
		document.id('menu3').setStyle('display', 'block');
		
		// reposition popups
		reposition();
	});
	// END MENU
});
