﻿/// <reference path="jquery-1.3.2.min.js"/>

OWL.slidingForms = OWL.slidingForms || {};

(function() {

	var that = OWL.slidingForms;

	var thatObj = {
		showYes: function(eventAffiliateID) {
			that.showFromUrl('/Concert/RegisterForEventControl/' + eventAffiliateID);
			that.saveClick(eventAffiliateID, true);
		},
		showNo: function(eventAffiliateID) {
			that.showFromUrl('/Concert/ProposeArtistControl/' + eventAffiliateID);
			that.saveClick(eventAffiliateID, false);
		},
		saveClick: function(eventAffiliateID, value) {
			try {
				$.ajax({
					type: "get",
					dataType: "html",
					url: '/Concert/AreYouInClick?YesClicked=' + value + '&EventAffiliateID=' + eventAffiliateID,
					cache: false,
					success: function(result) {
						//do nothing
					},
					error: function(xhr, textStatus, errorThrown) {
						//do nothing
					}
				});
			} catch (e) {
				//do nothing
			}
		},
		showFromUrl: function(url) {
			$.ajax({
				type: "get",
				dataType: "html",
				url: url,
				success: function(result) {

					jQuery("#registerForEventContainer")
						.empty()//clear contents
						.append(result)//set contents
					;
				},
				error: function(xhr, textStatus, errorThrown) {
					//show error
					//OWL.helpers.defaultErrorCallback(xhr, textStatus, errorThrown);
				}
			});
		},
		slideDown: function() {
			jQuery(".slidingForm").slideDown();
		},
		slideUp: function() {

			//reset slider state
			var swf = that.getFlashObject('yesNoSlider', 'FlashID');
			if (swf) {
				swf.resetSlider();
			}

			jQuery(".slidingForm").slideUp();
		},
		registerForEventSuccess: function(sender, targetID, result) {
			jQuery('#' + targetID)
				.empty()//clear contents
				.append(result)//set contents
				.animate({ opacity: 0.1 }, 000)//start opaque
				.animate({ opacity: 1.0 }, 750)//end at 1
			;

			if (jQuery('#' + targetID + ' form').length == 0) {
				//slide up if a form wasn't returned
				//	this means it submitted correctly
				setTimeout(that.slideUp, 2000);
			}
		},
		getFlashObject: function(firefoxID, ieID) {
			var swf;
			if (navigator.appName.indexOf("Microsoft") != -1) {
				swf = window[ieID];
			}
			else {
				swf = document[firefoxID];
			}
			return swf;
		},
		lastFunction: function() { }
	};

	OWL.lang.augmentObject(that, thatObj, true);
})();
