// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Apply rounded corners
window.onload = function() {
	Nifty("dt.round","big transparent right");
	Nifty("td.round","big transparent right");
	Nifty("div.roundleft", "big transparent left");
	Nifty("div.roundright", "big transparent right");
	Nifty("div#basket_header", "big transparent right");
	Nifty("li.package h2", "big transparent right");
};

TopUp.addPresets({
	"ul.video_links a": {
	  type: "flash",
		fixed: 0,
		modal: 0,
		width: '600px',
		height: '450px'
		//layout: Prototype.Browser.IE ? "dashboard" : "quicklook"
	}
});

function rebindTopUp() {
	TopUp.rebindTopUp();
}

function copy_checked_products() {
	var checked = $$('.product_check_box').findAll(function(n) { return n.checked; }).pluck('id');
	$('free_sample_product_ids').value = checked;
}

function refresh_calendar() {
	if (typeof(calendar) != "undefined" ) {
		calendar.refresh();
	}
}

Effect.ScrollTo = Class.create();
Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), {
	initialize: function(scrollelement, delta_argument, options) {
		this.scrollelement = $(scrollelement);
		this.delta = null;
		this.element = null;
		
		if (typeof delta_argument == 'number')
			this.delta = delta_argument;
		else
			this.element = $(delta_argument);
		
		this.start(options || {});
	},

	setup: function() {
		this.origin = this.scrollelement.scrollLeft;

		if (this.element != null) {
			var destination = this.element.offsetLeft - this.scrollelement.offsetLeft;
			this.delta = destination - this.scrollelement.scrollLeft;

			if (destination > this.scrollelement.style.width.split('px')[0])
				this.delta = this.delta - (this.scrollelement.style.width.split('px')[0] - this.element.style.width.split('px')[0]);
		}
	},

	update: function(position) {
		var offset = position * this.delta;
		this.scrollelement.scrollLeft = this.origin + offset;
	},

	finish: function(position) {
		// call function to hide left and right arrows
	}
});

function check_payment_issuer(message) {
  if ($('payment_issuer') == "undefined") {
    return true;
  } else {
    if ($('payment_issuer').value == "") {
      alert(message);
      return false;
    } else {
      return true;
    }    
  }
}

function toggleInvoiceAddress() {
  $('invoice_address').toggle();
}

function checkDeliveryCosts(message) {
  if ($('send_cost_id').value == "") {
    alert(message);
    return false;
  } else {
    return true 
  }
}
