var IconImagesSite = 
{
	onReady:	function()
	{
		// Set base path
		IconImagesSite.basePath = document.location.protocol + '//' + document.location.host;
	
		for (var selector in this.elements)
		{
			var $elms = $(selector);
			
			if ($elms.size() > 0)
			{
				this.elements[selector]($elms);
			}
		}
	},
	
	applyBehaviours: function($div)
	{
		var $elms = $(selector, $div);
			
		if ($elms.size() > 0)
		{
			this.elements[selector]($elms);
		}
	},
	
	elements:
	{
		'#album_selector': function($input){
            $input.change(function (){
                if($input.val() != '') {
                    window.location.replace($input.val());
                }
            });
		},

		
		'#OfflineSaleType': function($elms){
			
		
			/*
			 * Bind the onclick
			 */
			$('#offline_check_email_bttn').bind('click', function(e){			
					/*
					 * Ajax populate email result
					 */
					 //$('#UserEmail').html("<option> Please wait....</option>");
					$('#offline_email_result').html("Please wait...");
					$options = $.get("/carts/ajax_check_existing_user/" +  $('#CartEmail').val() + "/", 
								function(data){
									//console.log(data);
									switch (data){
										case 'found':
											$('#offline_email_result').html("Found this email <br/>Please proceed with customer details as required for Delivery.");
											$('#offline_customer_survey').css('display', '');
											//$('#CartDobMonth').val('');$('#CartDobDay').val('');('#CartDobYear').val('');('#CartGender').val('');
											break;
										case 'found/survey':
											$('#offline_email_result').html("Found this email <br/>Please proceed with customer details as required for Delivery.");
											$('#offline_customer_survey').css('display', 'none');
											//$('#CartTakingSurvey').val('no');
											break;
										case 'not_found':
											$('#offline_email_result').html("New customer <br/>Please proceed with customer details as required for Delivery.");
											$('#offline_customer_survey').css('display', '');
											//$('#CartTakingSurvey').val('yes');
											break;
										default:
											$('#offline_email_result').html("");
											$('#offline_customer_survey').css('display', '');
											//$('#CartTakingSurvey').val('yes');
											break;
									}
								}
					);
					e.stopPropagation();
					e.preventDefault();
					return false;
			});
			
		},
		
		
		
		
		'#checkin-html': function($elms){
		
			$('#checkin-html').click(function(){
				if($('#checkinListId').val()==0){
					alert("Please select an event before viewing your check-in list");
					
				}else{
					window.open(  '/promoter_users/attendee_list/' + ($('#checkinListId').val() + '/html') );
				}
			});
			$('#checkin-excel').click(function(){
				if($('#checkinListId').val()==0){
					alert("Please select an event before viewing your check-in list");
					
				}else{
					window.open(  '/promoter_users/attendee_list/' + ($('#checkinListId').val() + '/excel') );
				}
			});
			$('#checkin-pdf').click(function(){
				if($('#checkinListId').val()==0){
					alert("Please select an event before viewing your check-in list");
					
				}else{
					window.open(  '/promoter_users/attendee_list/' + ($('#checkinListId').val() + '/pdf') );
				}
			});
		
		},
		
	
		'#EventAddForm': function ($elms){
			$('#EventAddForm input[id^="editSectionButton"]').click(function(){
		
					//get the id number for this button/section (i.e. editSectionButton365 => 365)
					var section_id = this.id.substring(17,this.id.length);
					
					//expand this items section
					//the callback function on the end is simply an ie7 bugfix workaround
					$('#eventSectionFields'+section_id).slideDown("slow",function(){ $('#eventSectionFields'+section_id).fadeTo(100,1) });
				
					
					//hide the edit button and show the close button for this section 
					$('#closeSectionButton'+section_id).css('display','');
					$('#editSectionButton'+section_id).css('display','none');

					//hide all other "close" buttons, and show edit buttons instead
					$('input[id^="closeSectionButton"][id!="closeSectionButton'+section_id+'"]').css('display','none');
					$('input[id^="editSectionButton"][id!="editSectionButton'+section_id+'"]').css('display','');


					//close all other sections
					$('div[id^="eventSectionFields"][id!="eventSectionFields'+section_id+'"]').slideUp();
					
			});

			$('#EventAddForm input[id^="closeSectionButton"]').click(function(){

					//get the id number for this button/section (i.e. closeSectionButton365 => 365)
					var section_id = this.id.substring(18,this.id.length);
					
					//close this section
					$('#eventSectionFields'+section_id).slideUp();

					//hide the close button and show the edit button for this section 
					$('#closeSectionButton'+section_id).css('display','none');
					$('#editSectionButton'+section_id).css('display','');
					
			});
			
			$('#EventAddForm input[id^="deleteSectionButton"]').click(function(){

					//get the id number for this button/section (i.e. closeSectionButton365 => 365)
					var section_id = this.id.substring(19,this.id.length);
					
					//close this section
					$('#eventSection'+section_id).slideUp();

					//set the variable to ensure this section will be deleted on form submission 
					$('#eventSection'+section_id+' #EventSectionDeleteMe').attr('value','1');					
					
			});
		},
		'#site_name a': function ($elms) 
		{
			
		},

		'#search-form': function ($elms)
		{
			initSearchForm();
		},
				
		'#recent_news':	function ($elms)
		{
		},
		
		'#searchField': function ($elms)
		{
			initAutoComplete('#searchField');
		},
		
		
		'form' : function ($elms)
		{
			var submitted = false;
			$elms.bind('submit',
				function(e)
				{
					if (!submitted)
					{
						submitted = true;
						return true;
					}
					else
					{
						e.preventDefault();
						e.stopPropagation();
						return false;
					}
					//$('input[type=submit], button', this).attr('disabled',true);
				}
			);
		},
		
		
		
		//	WYSIWYG Editor functionality
		'textarea.wysiwyg_editor': function($elms)
		{
		
			$elms = $elms.eq(0);
		
			//var fckeditor_base_path = IWannaTicketSite.basePath + '/js/fckeditor/';
			var fckeditor_base_path = '/js/fckeditor/';
			var styles_path = $('link[ @href$=iwannaticket_template.css]:first').attr('href');
			
					$elms.each(
						function()
						{
							var editor = new FCKeditor( this.id ) ;
							editor.BasePath	= fckeditor_base_path ;
							editor.Config['EditorAreaCSS'] = styles_path;
							editor.ToolbarSet = 'Default';
							editor.Height = 400;
							editor.ReplaceTextarea() ;
						}
					);
				
			
		}
		
		/*
		'#refresh_event_detail': function ($elms)
		{
		
			$('#refresh_event_detail').click(function(){
				$('#refresh_event_detail').parents('[id*=\'ajax-element\']:first').load('/events/view/id:'+$('#EventId').val()+'/locations:'+$('#EventLocations').val()+'/dates:'+$('#EventDates').val()+'/event_sections:'+$('#EventEventSections').val()+'/quantity:'+$('#EventQuantities').val()+'/');
			});
		}
		*/
		
		
		
	}
}

$(document).ready(
	function()
	{		
		IconImagesSite.onReady();
    }
);

	
	
