var pmdro = {};

// function has problems in IE
pmdro.setWrapHeight = function() {
	var wrapPaddingTop = parseInt(this.wrap.css('padding-top'));
	var wrapPaddingBottom = parseInt(this.wrap.css('padding-bottom'));
	var wrapHeight = Math.max($(window).height(), this.documentHeight) - wrapPaddingTop - wrapPaddingBottom;
  this.wrap.height(wrapHeight);
};

pmdro.switchStyleSheet = function(styleName) {
  $('link[@rel*=style][id]').each(function(i) {
    this.disabled = true;
    if (this.getAttribute('id') == styleName) this.disabled = false;
  });
};

pmdro.positionShowCaseCtrls = function() {
	var showcase = $('#showcase');
	var prev = $('#showcase-prev');
	var next = $('#showcase-next');

	var t = showcase.offset().top + (showcase.height() / 2) - (prev.height() / 2) + 'px';
	var l = showcase.offset().left - (prev.width() / 2) + 'px';
	var r = showcase.offset().left + showcase.width() - (prev.width() / 2) + 'px';
	prev.css({'top':t,'left':l});
	next.css({'top':t,'left':r});
};

pmdro.cycleShowCase = function() {
	var showcase = $('#showcase');
	showcase.after('<div class="cycle-controls"><div id="showcase-prev" class="cycle-prev"></div><div id="showcase-next" class="cycle-next"></span></div>');
	this.positionShowCaseCtrls();
	showcase.cycle({
	    fx: 'scrollHorz',
	    prev: '#showcase-prev',
	    next: '#showcase-next',
	    timeout: 0,
	    speed: 1000,
	    easing: 'easeInOutBack'
	});
};

$(function(){
	pmdro.ie6 = ($.browser.msie && $.browser.version < 7);
	if (pmdro.ie6) { pmdro.switchStyleSheet('css-ie6'); }
	
  pmdro.documentHeight = $(document).height();
  pmdro.wrap = $('#wrap');
  
  pmdro.setWrapHeight();
  
  window.onresize = function() {
    pmdro.setWrapHeight();
		pmdro.positionShowCaseCtrls();
  }
});