// Author: darryl hebbes darryl@consology.com
// Requirements

 // jQuery API (ver 1.3.2) (jquery.com)
 // ----------
 // jcarousellite_1.0.1.js 
 // (Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com))
 // http://www.gmarwaha.com/jquery/jcarousellite/#doc
 // ----------
 // reflection.js
 // (c) 2006-2008 Christophe Beyls <http://www.digitalia.be>
 // MIT-style license.

$j.em = $j.em || {
 VER:0.3,
 ASSET_PATH:'elements/'
};

$j.em.movie = $j.em.movie || {};

$j.em.cart = $j.em.cart || {
 state:0
};

$j.em.carousel = $j.em.carousel || {
 startItem:9,
 DIR_CLICKED:'N'
};

$j.em.carousel.init = function() {
 if (jQuery.browser.msie) {
 $j(".current_class:eq(0)").trigger("click");
 var css_class = $j(".current_class").attr("class");
 if (css_class) {
 temp_css_class = css_class.split(" ");
 temp_css_class1 = temp_css_class[1].split("_");
 prod_id = temp_css_class1[1];
 $j("#"+prod_id).parent('div').parent('li').find('.selected_image_class').css("display", "block");
 $j.getProductDetails(prod_id);
 }
 }
 else {
 var css_class = $j(".current_class").attr("class");
 if (css_class) {
 temp_css_class = css_class.split(" ");
 temp_css_class1 = temp_css_class[1].split("_");
 prod_id = temp_css_class1[1];
 $j("#"+prod_id).parent('div').parent('li').find('.selected_image_class').css("display", "block");
 $j.getProductDetails(prod_id);
 }
 } 
};

/* Homepage cart namespace */
$j.em.cart.init = function() {};

/*
$j.em.cart.addSelectedTitle = function() {
 var addcartitemindx = $j("body").data("selected_title").product_id;
 var indx = $j("body").data("selected_title").cindex;
 var addcartitemtitle = $j("body").data("selected_title").ctitle;
 if ($j('input#chkout_'+addcartitemindx).length > 0) {
 alert('Shopping Cart Notification:\n "'+addcartitemtitle+'" is already added.');
 return false;
 }
 //$j('#checkout_form ul').prepend('<li><input type="checkbox" id="chkout_'+addcartitemindx+'" class="added-item" value="'+addcartitemindx+'"/><a href="javascript:$j.em.cart.TriggerCartItem('+addcartitemindx+');">'+addcartitemtitle+'</a></li>');
 $j('#checkout_form ul').prepend('<li><input type="checkbox" id="chkout_'+addcartitemindx+'" name="product[]" class="added-item" value="'+addcartitemindx+'"/><a href="javascript:$j.em.cart.TriggerCartItem('+indx+');">'+addcartitemtitle+'</a></li>');
 $j.em.cart.setCartDisplay();
}; */

$j.em.cart.removeSelectedTitles = function() {
 if ($j("#checkout_form input:checked").length > 0) {
 $j("#checkout_form input:checked").each(function() {
 $j(this).parents('li').remove();
 var id = $j(this).attr("id");
 $j.ajax({
 type: "GET",
 url: base_path+"checkout/cart/delete",
 data: "id="+id,
 success: function(msg){
 var url = base_path; 
 //$j(location).attr('href',url);
 }
 });
 
 });
 $j.em.cart.setCartDisplay();
 toggleRemoveBtns();

 } else {
 alert("Shopping Cart Notification:\n You have not selected any items to remove.");
 }


};

$j.em.cart.removeAllTitles = function() {
 $j("#checkout_form input[type='checkbox']").each(function() {
 var id = $j(this).attr("id");
 $j.ajax({
 type: "GET",
 url: base_path+"checkout/cart/delete",
 data: "id="+id,
 success: function(msg){
 var url = base_path; 
 //$j(location).attr('href',url);
 }
 });
 $j(this).parents('li').remove();
 });
 $j.em.cart.setCartDisplay();
 toggleRemoveBtns();
};

$j.em.cart.visibleToggle = function() {
 if ($j.em.cart.state==0){
 toggleProductPane(0);
 return false;
 }
 if ($j.em.cart.state==1) {
 toggleProductPane(1);
 return false;
 }
};

$j.em.cart.TriggerCartItem = function(idemid) {
 $j("#title_que li.t"+idemid).click();
}

$j.em.cart.setCartDisplay = function() {
 var ITEM_COUNT = parseInt($j("#checkout_form input.added-item").length); 
 var s;
 if (ITEM_COUNT ==0){
 s = '';
 $j.em.cart.state = 0;
 $j.em.cart.visibleToggle();
 $j('div.checkout-form-status span.heading').html('Shopping Cart');
 } else if (ITEM_COUNT==1){
 s = ITEM_COUNT+' item';
 $j.em.cart.state = 1;
 $j.em.cart.visibleToggle();
 $j('div.checkout-form-status span.heading').html('Selected Films'); 
 } else if (ITEM_COUNT>1){
 s = ITEM_COUNT+' items';
 $j.em.cart.state = 1;
 $j.em.cart.visibleToggle();
 $j('div.checkout-form-status span.heading').html('Selected Films'); 
 };
 $j('div.checkout-form-status span.count').html(s); 
};


Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i] == value) {
return i;
}
}
return ctr;
};
$j.em.cart.getSelectedProducts = function(url) {
 var productIDs = '';
 //if ($j("#checkout_form input:checked").length > 0){
 $j("#checkout_form input").each(function() {
 productIDs = productIDs + $j(this).val() + ',';
 });
 //}
 $j("#selectedProductIDs").val(productIDs);
 if (!jQuery.em.cart.hasItem())
 {
 return false;
 }
 window.location = url;
 };
jQuery.em.cart.hasItem= function() {
 
 var ITEM_COUNT = parseInt(jQuery("#checkout_form input.added-item").length);
 if (ITEM_COUNT == 0){
 alert("Shopping Cart Notification:\n You don't have any item to checkout.");
 return false;
 }
 else { 
 if ($j("input#checkout").attr('id')=="checkout") {
 $j("input#checkout").attr('class','thickbox button right1 set');
 tb_show(null,$j("input#checkout").attr('alt'),false);
 $j("input#checkout").blur();
 }
 return true;
 }

}


function toggleRemoveBtns() {
 if($j("#checkout_form input[type='checkbox']").length>0) {
 $j("a#removeselected_id").css('display','');
 $j("div#disablebtn_removeselected").css('display','none');
 $j("input#removeall_id").css('display','');
 $j("div#disablebtn_removeall").css('display','none');
 if ($j("input#checkoutnew"))
 {
 $j("input#checkoutnew").css('display','block');
 }
 if ($j("a#checkout"))
 {
 $j("a#checkout").css('display','block');
 }
 $j("div#disablebtn_checkout").css('display','none');
 }
 else {
 $j("a#removeselected_id").css('display','none');
 $j("div#disablebtn_removeselected").css('display','');
 $j("input#removeall_id").css('display','none');
 $j("div#disablebtn_removeall").css('display','');
 if ($j("input#checkoutnew"))
 {
 $j("input#checkoutnew").css('display','none');
 }
 if ($j("a#checkout"))
 {
 $j("a#checkout").css('display','none');
 }
 $j("div#disablebtn_checkout").css('display','block');
 }
}

function addtocartCalled(product_id)
{ 
 //var addcartitemtitle = $j("body").data("selected_title").ctitle;
 var addcartitemtitle = $j("#"+product_id).attr('alt');
 
 var continue1 = true;
 $j("input.added-item").each(function(){
 var value = $j(this).val();
 if (value == product_id) {
 $j("#addtocart-please-wait").css('visibility','hidden');
 alert('Shopping Cart Notification:\n "'+addcartitemtitle+'" is already added.');
 continue1 = false;
 }
 else {
 //$j("#addtocart-please-wait").css('display','');
 showLoader();
 }

 });

 if (continue1 == true) {
 $j("#addtocart-please-wait").css('visibility','visible');
 $j.ajax({
 type: "POST",
 url: base_path+"paramount/product/addproduct",
 data: "product="+product_id,
 success: function(msg){
 var url = base_path; 
 //$j(location).attr('href',url);
 $j('#cart-items').html(msg);
 showProductPane();
 $j.em.cart.setCartDisplay();
 }
 });
 }
}

 function showLoader()
 {
 Element.show('addtocart-please-wait');
 // Element.setStyle('addtocart-buttons-container', {opacity:.5});
 }
 function showProductPane() {
 $j('#disablebtn_removeselected').css("display","none");
 $j('#removeselected_id').css("display","");
 $j('#disablebtn_removeselected').css("display","none");
 $j('#removeall_id').css("display","");
 if ($j("input#checkoutnew"))
 {
 $j("input#checkoutnew").css('display','');
 }
 if ($j("a#checkout"))
 {
 $j("a#checkout").css('display','');
 }
 $j("div#disablebtn_checkout").css('display','none');
 $j('#addtocart-please-wait').css("visibility","hidden");
 $j('#disablebtn_removeall').css("display","none");
 toggleProductPane(1);
 }

function toggleProductPane(cartState) {
 if (cartState==0){
 $j('div#move_info').animate({"height":284}, 200);
 $j('div.checkout-form').animate({"height":0}, 200);
 $j('div.checkout-form-handle a').html('<span class="less">less</span>&nbsp;');
 /*$j("tr#director").css("display","");
 $j("tr#running_time").css("display","");
 $j("tr#genre").css("display","");*/
 $j("tr#rating").css("display","");
 $j("tr#cast").css("display","");
 $j.em.cart.state=1;
 }
 if (cartState==1) {
 $j('div#move_info').animate({"height":203}, 200);
 $j('div.checkout-form').animate({"height":80}, 200); 
 $j('div.checkout-form-handle a').html('<span class="more">more</span>&nbsp;');
 $j("tr#director").css("display","none");
 $j("tr#running_time").css("display","none");
 $j("tr#genre").css("display","none");
 $j("tr#rating").css("display","none");
 $j("tr#cast").css("display","none");
 $j.em.cart.state=0;
 }
}

/* 
 * 
 * Copyright (c) 2007 e-nova technologies pvt. ltd. (kevin.muller@enova-tech.net || http://www.enova-tech.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * __ ___ ___ __ __ __ 
 * /'__`\ __ /' _ `\ / __`\ /\ \/\ \ /'__`\ 
 * /\ __/ /\__\ /\ \/\ \ /\ \_\ \\ \ \_/ |/\ \_\.\_ 
 * (o_ \ \____\ \/__/ \ \_\ \_\\ \____/ \ \___/ \ \__/.\_\ _o)
 * (/)_ \/____/ \/_/\/_/ \/___/ \/__/ \/__/\/_/ _(\)
 * 
 * Prevents Headaches ! 
 * 
 * JMyCarousel is inspired and based on JCarouselLite, an original concept by Ganeshji Marwaha
 * 
 *
 * $LastChangedDate: 2007-06-22 20:08:34 -0500 (Thu, 22 Nov 2007) $
 * $Rev: 15 $
 *
 * Version: 0.1
 */

(function ( $ ) { // Compliant with jquery.noConflict()
$.fn.jMyCarousel = function(o) { 
 o = $.extend({
 btnPrev: null, // previous button customization
 btnNext: null, // next button customization
 mouseWheel: true, // shall the carousel handle the mousewheel event to animate ?
 auto: false, // shall the carousel start automatically

 speed: 800, // speed in ms of the animation.
 easing: 'linear', // linear animation.

 vertical: false, // set the carousel in a vertical mode
 circular: false, // run in circular mode. Means : images never reach the end.
 visible: '4', // size of the carousel on the screen. Can be in percent '100%', in pixels '100px', or in images '3' (for 3 images)
 start: 0, // position in pixels that the carousel shall start at
 scroll: 1,
 
 step: 50, // value in pixels, or "default"
 eltByElt: false, // if activated, the carousel will move image by image, not more, not less.
 evtStart : 'mouseover', // start event that we want for the animation (click, mouseover, mousedown, etc..)
 evtStop : 'mouseout', // stop event that we want for the animation (blur, mouseout, mouseup, etc..)
 beforeStart: null, // Not used yet
 afterEnd: null // Not used yet
 }, o || {});


 return this.each(function() { // Returns the element collection. Chainable. 
 o.start = parseInt(temp_start);
 var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
 var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;
 var mousewheelN = 0; // will help for the mousewheel effect (to count how many steps we have to walk ahead)
 var defaultBtn = (o.btnNext === null && o.btnPrev === null) ? true : false;
 var cssU = (v.toString().indexOf("%") != -1 ? '%' : (v.toString().indexOf("px") != -1) ? 'px' : 'el');
 var direction = null; // used to keep in memory in which direction the animation is moving
 
 // circular mode management
 // we add at the end and at the beginning some fake images to make the circular effect more linear, so it never breaks
 // It is still possible to improve the memory management by adding exactly the number of images requested.
 if(o.circular) {
 var imgSet = tLi.clone();
 ul.prepend(imgSet).append(imgSet.clone());
 }
 
 var li = $("li", ul); // list 
 div.css("visibility", "visible");
 li.css("overflow", "hidden") // If the list item size is bigger than required
 .css("float", o.vertical ? "none" : "left") // Horizontal list
 .children().css("overflow", "hidden"); // If the item within li overflows its size, hide'em
 if(!o.vertical){ li.css("display", "inline"); } // IE double margin bug - rooo..
 if(li.children().get(0).tagName.toLowerCase() == 'a' && !o.vertical){
 li.children().css('float','left');
 }
 if(o.vertical && jQuery.browser.msie){ // Hack IE (again..) / purpose is to cancel the white space below the image when the carousel is in vertical mode
 // The issue comes up when li is not in float:left. so we put it in float:left and adjust the size
 li.css('line-height', '4px').children().css('margin-bottom', '-4px');
 }
 

 ul.css("margin", "0") // Browsers apply default margin 
 .css("padding", "0") // and padding. It is reset here.
 .css("position", "relative") // IE BUG - width as min-width
 .css("list-style-type", "none") // We dont need any icons representing each list item.
 .css("z-index", "1"); // IE doesnt respect width. So z-index smaller than div

 div.css("overflow", "hidden") // Overflows - works in FF
 .css("position", "relative") // position relative and z-index for IE
 .css("z-index", "2") // more than ul so that div displays on top of ul
 .css("left", "0px"); // after creating carousel show it on screen
 
 var liSize = o.vertical ? height(li) : width(li); // Full li size(incl margin)-Used for animation
 var liSizeV = o.vertical ? elHeight(li) : height(li); // size of the main layer, in its side 
 var curr = o.start; // Current position in pixels 
 var nbAllElts = li.size(); // Total number of items 
 var ulSize = liSize * nbAllElts; // size of full ul(total length, not just for the visible items)
 var nbElts = tl; // number of elements (only visible items)
 var eltsSize = nbElts * liSize; // size of the visible elements only
 var allEltsSize = nbAllElts * liSize; // Total size of the elements
 //var jmcSize = jmcSize(); // Size of the carousel
 var step = o.step == 'default' ? liSize : o.step; // step size
 
 //debug("liSize=" + liSize + "; liSizeV=" + liSizeV + "; curr=" + curr + "; visible : " + liSize * v); // debug
 o.btnPrev = defaultBtn ? $('<input type="button" class="' + (o.vertical ? 'up' : 'prev') + '" />') : $(o.btnPrev);
 o.btnNext = defaultBtn ? $('<input type="button" class="' + (o.vertical ? 'down' : 'next') + '" />') : $(o.btnNext);
 var prev = o.btnPrev;
 var next = o.btnNext;
 
 /******* Buttons **********/
 if(defaultBtn && o.auto !== true){ //Add buttons when necessary (In default mode and not auto)
 prev.css({'opacity':'0.6'});
 next.css({'opacity' :'0.6'});
 div.prepend(prev);
 div.prepend(next);
 o.btnPrev = prev;
 o.btnNext = next;
 }
 
 // Element by element management (eltBYElt = true)
 if(o.eltByElt){ 
 step = liSize; // the step size is necessarily the size of the element
 if(o.start % liSize !== 0){ // If a start position was given and was not exactly positionned between 2 images
 var imgStart = parseInt(o.start / liSize); // we adjust it
 curr = o.start = (imgStart * liSize); // we set the starting position at a fixed point, between 2 images.
 }
 }
 
 // Adjust the start position in case of circular mode
 if(o.circular){
 o.start += (liSize * tl); // The start position is one carousel length ahead due to the optical effect
 curr += (liSize * tl); // used for the animation
 }
 
 // Calculates the size of the main div according to the given size (can be in percent, in value or in pixels)
 var divSize, cssSize, cssUnity;
 if(cssU == '%'){ // in percent 
 divSize = 0; // We don't have the value in pixels unless we set the percent value first. So 0, and will catch it later
 cssSize = parseInt(v); 
 cssUnity = "%";
 }
 else if(cssU == 'px'){ // in pixels
 divSize = parseInt(v);
 cssSize = parseInt(v);
 cssUnity = "px";
 }
 else{ // in elements (number of elements to display)
 divSize = liSize * parseInt(v); 
 cssSize = liSize * parseInt(v);
 cssUnity = "px";
 } 

 // Adjust the carousel size with the correct values
 //li.css("width", imgSize(li, 'width')) // inner li width. this is the box model width
 //.css("height", imgSize(li), 'height'); // inner li height. this is the box model height
 ul.css(sizeCss, ulSize + "px") // Width of the UL is the full length for all the images
 .css(animCss, -(o.start)); // Set the starting item
 div.css(sizeCss, cssSize + cssUnity); // Width of the DIV. length of visible images
 if(o.vertical && cssUnity == '%'){ // Bugfix - % in vertical mode are badly handled by the browsers
 var pxsize = ((liSize * nbElts) * (parseInt(v) / 100));
 div.css(sizeCss, pxsize + 'px'); // The height of the carousel is based on the visible elements size
 }
 
 if(divSize === 0){ // We didn't have the size in pixels in case of % size. Catch up !
 divSize = div.width(); // The size is simply the calculated size in pixels
 }
 
 // Adjust the height of the carousel (width in vertical mode)
 if(o.vertical){ // vertical mode
 div.css("width" , liSizeV + 'px');
 ul.css("width", liSizeV + 'px');
 li.css('margin-bottom', (parseInt(li.css('margin-bottom')) * 2) + 'px'); // bypass the "margin collapsing" effect by multiplying the margin-bottom by 2 
 li.eq(li.size() - 1).css('margin-bottom', li.css('margin-top')); // Last element has to be the right margin since no margin collapse there
 }else{ // horizontal mode
 //div.css('height', liSizeV + 'px');
 //ul.css('height', liSizeV + 'px'); 
 }
 
 // Calculate the number of visible elements inside (in case of size in percent) 
 if(cssU == '%'){
 v = divSize / li.width(); 
 if(v % 1 !== 0){ v +=1; }
 v = parseInt(v);
 }
 
 var divVSize = div.height(); // div height
 
 ////////////////////////
 // Buttons management //
 ////////////////////////
 if(defaultBtn){
 next.css({'z-index':200, 'position':'absolute'});
 prev.css({'z-index':200, 'position':'absolute'});
 //Positionate the arrows and adjust the arrow images
 if(o.vertical){
 prev.css({'width': prev.width(), 'height' : prev.height(), 'top' : '0px', 'left': parseInt(liSizeV / 2) - parseInt(prev.width() / 2) + 'px'});
 next.css({'width': prev.width(), 'height' : prev.height(), 'top' : (divVSize - prev.height()) + 'px', 'left' : parseInt(liSizeV / 2) - parseInt(prev.width() / 2) + 'px'});
 
 }
 else{
 prev.css({'left':'0px', 'top': parseInt(liSizeV / 2) - parseInt(prev.height() / 2) + 'px'});
 next.css({'right':'0px', 'top': parseInt(liSizeV / 2) - parseInt(prev.height() / 2) + 'px'});
 }
 }

 /*jQuery(".jMyCarousel ul li img").click(function(e) {
 var move = 0;
 var tempX = e.pageX;
 var temp = parseInt(tempX / liSize);
 if (temp < 6) {
 move = 6 - temp;
 direction = 'backward';
 return backward(move*liSize, true); 
 }
 if (temp > 6) {
 move = temp - 6;
 direction = 'forward';
 return forward(move*liSize, true); 
 } 
 }); */

 // Bind the events with the "previous" button
 if(o.btnPrev){ 
 $(o.btnPrev).bind(o.evtStart, function() {
 if(defaultBtn){ o.btnPrev.css('opacity',0.9); }
 running = true;
 direction = 'backward';
 return backward(); 
 });
 
 $(o.btnPrev).bind(o.evtStop, function() {
 if(defaultBtn){ o.btnPrev.css('opacity',0.6); }
 running = false; 
 direction = null;
 return stop(); 
 });
 }
 
 
 // Bind the events with the "next" button
 if(o.btnNext){
 $(o.btnNext).bind(o.evtStart, function() {
 if(defaultBtn){ o.btnNext.css('opacity',0.9); }
 running = true;
 direction = 'forward';
 return forward(); 
 });
 $(o.btnNext).bind(o.evtStop,function() {
 if(defaultBtn){ o.btnNext.css('opacity',0.6); }
 running = false;
 direction = null;
 return stop(); 
 });
 }
 
 // auto scroll management (auto = true). => launch the animation
 if(o.auto === true){
 running = true; 
 forward(); 
 } 

 // Mousewheel management 
 if(o.mouseWheel && div.mousewheel){
 div.mousewheel(function(e, d) { 
 if(!o.circular && (d > 0 ? (curr + divSize < ulSize) : (curr > 0)) || o.circular){ //prevents the mouse events to occur in case of circular mode
 mousewheelN += 1; //one more step to do, store it.
 if(running === false){
 if(d > 0){ forward(step, true); }
 else { backward(step, true); }
 running = true;
 }
 }
 });
 }
 
 /**
 * Animate the track by moving it forward according to the step size and the speed
 * @param stepsize, the size of the step (optional)
 * @param once, shall the animation continue endlessly until we set running to false ? (optional)
 */
 function forward(stepsize, once){
 var s = (stepsize ? stepsize : step);

 if(running === true && direction === "backward"){ return; }
 
 //If not circular, no need to animate endlessly
 if(!o.circular){
 //will the next step overtake the last image ?
 if(curr + s + (o.vertical ? divVSize : divSize) > eltsSize){
 s = eltsSize - (curr + (o.vertical ? divVSize : divSize));
 }
 }
 
 ul.animate(
 animCss == "left" ? { left: -(curr + s) } : { top: -(curr + s) } , o.speed, o.easing,
 function() {
 curr += s; //Add step size
 //Calculate whether we cross the limit,
 //if so, put the carousel one time backward
 if(o.circular){
 if(curr + (o.vertical ? divVSize : divSize) + liSize >= allEltsSize){
 ul.css(o.vertical ? 'top' : 'left', -curr + eltsSize);
 curr -= eltsSize;
 }
 }
 
 if(!once && running){
 forward();
 }
 else if(once){
 if(--mousewheelN > 0){
 this.forward(step, true);
 }
 else{
 running = false;
 direction = null;
 }
 }
 }
 );
 }
 
 /**
 * Animate the track by moving it backward according to the step size and the speed
 * @param stepsize, the size of the step (optional)
 * @param once, shall the animation continue endlessly until we set running to false ? (optional)
 */
 function backward(stepsize, once){
 var s = (stepsize ? stepsize : step);
 
 if(running === true && direction === "forward"){ return; } 
 
 //If not circular, no need to animate endlessly
 if(!o.circular){
 //will the next step overtake the first image ?
 if(curr - s < 0){
 s = curr - 0;
 }
 }
 
 ul.animate(
 animCss == "left" ? { left: -(curr - s) } : { top: -(curr - s) } , o.speed, o.easing,
 function() {
 curr -= s;
 //Calculate if we cross the limit,
 //if so, put the carousel one time backward
 if(o.circular){
 if(curr <= liSize){
 ul.css(o.vertical ? 'top' : 'left', -(curr + eltsSize));
 curr += eltsSize;
 }
 }
 
 if(!once && running){
 backward();
 }
 else if(once){
 if(--mousewheelN > 0){
 backward(step, true);
 }
 else{
 running = false;
 direction = null;
 }
 }
 }
 );
 }
 /**
 * Stops the animation
 * Basically, tells the animation not to continue
 */
 function stop(){
 if(!o.eltByElt){ //If we don't move elements by elements, then we can stop immediately
 ul.stop(); // stop the animation straight
 curr = 0 - parseInt(ul.css(animCss)); // We stopped suddenly, so the curr variable is not refreshed. We refresh it with the true value
 }
 running = false; // default value and in case we proceed element by element (eltByElt = true)
 direction = null;
 }
 
 /**
 * Return the size of the carousel, everything included (height or length depending on o.vertical)
 */
 /*function jmcSize(){
 var img = $('ul li img', div);
 var sizeLi = (o.vertical ? img.width() : img.height());
 var elt = img;
 while(elt.parent().get(0).tagName.toLowerCase() != 'div'){
 sizeLi += (o.vertical ? (parseInt(elt.css('marginLeft')) + parseInt(elt.css('marginRight')) + parseInt(elt.css('paddingRight')) + parseInt(elt.css('paddingLeft'))) : (parseInt(elt.css('marginTop')) + parseInt(elt.css('marginBottom')) + parseInt(elt.css('paddingTop')) + parseInt(elt.css('paddingBottom'))));
 elt = elt.parent();
 } 
 return sizeLi;
 }*/
 
 /**
 * Calculate and return the size of the image in the element
 * @param el, the element
 * @param dimension, 'width' or 'height'.
 * @return the requested size in pixels.
 */
 function imgSize(el, dimension){
 if(dimension == 'width'){
 return el.find('img').width();
 }
 else {
 return el.find('img').height();
 }
 }
 
 /**
 * Size of an element li with its margin calculated from scratch (without any call to width except for the image size)
 * usefull in case of vertical carousel, when the size of each element is 100%.
 * @param el, the element
 * @return the size of the element in pixels
 */
 function elHeight(el){
 var elImg = el.find('img');
 if(o.vertical){
 return parseInt(el.css('margin-left')) + parseInt(el.css('margin-right')) + parseInt(elImg.width()) + parseInt(el.css('border-left-width')) + parseInt(el.css('border-right-width')) + parseInt(el.css('padding-right')) + parseInt(el.css('padding-left'));
 } 
 else{
 return parseInt(el.css('margin-top')) + parseInt(el.css('margin-bottom')) + parseInt(elImg.width()) + parseInt(el.css('border-top-height')) + parseInt(el.css('border-bottom-height')) + parseInt(el.css('padding-top')) + parseInt(el.css('padding-bottom'));
 }
 }
 
 function debug(html){
 $('#debug').html($('#debug').html() + html + "<br/>");
 } 
 
 });
};

function css(el, prop) {
 return parseInt($.css(el[0], prop)) || 0;
}

function width(el) {
 return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
}

function height(el) {
 return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
}



})(jQuery);
var $j = jQuery.noConflict(); 

$j(document).ready(function(){
 $j("input#firstname,input#lastname,input#email_address").keyup(function(){
 var length = $j(this).val().length;
 if(length > 64)
 {
 var val = $j(this).val();
 $j(this).val(val.substring(0,64));
 return false;
 }
 });
});


/*
 * Thickbox 3 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

var tb_pathToImage = "/js/jquery/elements/ui_modal/loadingAnimation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$j(document).ready(function($){ //$j(document).ready(function(){ 
 
 tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
 imgLoader = new Image();// preload image
 imgLoader.src = tb_pathToImage;
 var baseURL='';
 if (document.getElementById("baseurlid"))
 {
 baseURL = document.getElementById("baseurlid").value;
 imgLoader.src = baseURL + tb_pathToImage;
 }
 /* var url = location.href; // entire url including querystring - also: window.location.href;
 var baseURL = url.substring(0, url.indexOf('/', 14));
 imgLoader.src = baseURL + tb_pathToImage;*/
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
 $j(domChunk).click(function(){
 var t = this.title || this.name || null;
 var a = this.href || this.alt;
 var g = this.rel || false;
 tb_show(t,a,g);
 this.blur();
 return false;
 });
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

 try {
 if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
 $j("body","html").css({height: "100%", width: "100%"});
 $j("html").css("overflow","hidden");
 if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
 $j("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
 //$j("#TB_overlay").click(tb_remove);
 }
 }else{//all others
 if(document.getElementById("TB_overlay") === null){
 $j("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
 //$j("#TB_overlay").click(tb_remove);
 }
 }
 
 if(tb_detectMacXFF()){
 $j("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
 }else{
 $j("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
 }
 if(caption===null){caption="";}
 $j("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
 $j('#TB_load').show();//show loader
 
 var baseURL;
 if(url.indexOf("?")!==-1){ //ff there is a query string involved
 baseURL = url.substr(0, url.indexOf("?"));
 }else{ 
 baseURL = url;
 }
 
 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
 var urlType = baseURL.toLowerCase().match(urlString);

 if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
 
 TB_PrevCaption = "";
 TB_PrevURL = "";
 TB_PrevHTML = "";
 TB_NextCaption = "";
 TB_NextURL = "";
 TB_NextHTML = "";
 TB_imageCount = "";
 TB_FoundURL = false;
 if(imageGroup){
 TB_TempArray = $j("a[@rel="+imageGroup+"]").get();
 for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
 var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
 if (!(TB_TempArray[TB_Counter].href == url)) { 
 if (TB_FoundURL) {
 TB_NextCaption = TB_TempArray[TB_Counter].title;
 TB_NextURL = TB_TempArray[TB_Counter].href;
 TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
 } else {
 TB_PrevCaption = TB_TempArray[TB_Counter].title;
 TB_PrevURL = TB_TempArray[TB_Counter].href;
 TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
 }
 } else {
 TB_FoundURL = true;
 TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length); 
 }
 }
 }

 imgPreloader = new Image();
 imgPreloader.onload = function(){ 
 imgPreloader.onload = null;
 
 // Resizing large images - orginal by Christian Montoya edited by me.
 var pagesize = tb_getPageSize();
 var x = pagesize[0] - 150;
 var y = pagesize[1] - 150;
 var imageWidth = imgPreloader.width;
 var imageHeight = imgPreloader.height;
 if (imageWidth > x) {
 imageHeight = imageHeight * (x / imageWidth); 
 imageWidth = x; 
 if (imageHeight > y) { 
 imageWidth = imageWidth * (y / imageHeight); 
 imageHeight = y; 
 }
 } else if (imageHeight > y) { 
 imageWidth = imageWidth * (y / imageHeight); 
 imageHeight = y; 
 if (imageWidth > x) { 
 imageHeight = imageHeight * (x / imageWidth); 
 imageWidth = x;
 }
 }
 // End Resizing
 
 TB_WIDTH = imageWidth + 60; // default + 30
 TB_HEIGHT = imageHeight + 60;
 $j("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 
 
 $j("#TB_closeWindowButton").click(tb_remove);
 
 if (!(TB_PrevHTML === "")) {
 function goPrev(){
 if($j(document).unbind("click",goPrev)){$j(document).unbind("click",goPrev);}
 $j("#TB_window").remove();
 $j("body").append("<div id='TB_window'></div>");
 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
 return false; 
 }
 $j("#TB_prev").click(goPrev);
 }
 
 if (!(TB_NextHTML === "")) { 
 function goNext(){
 $j("#TB_window").remove();
 $j("body").append("<div id='TB_window'></div>");
 tb_show(TB_NextCaption, TB_NextURL, imageGroup); 
 return false; 
 }
 $j("#TB_next").click(goNext);
 
 }

 document.onkeydown = function(e){ 
 if (e == null) { // ie
 keycode = event.keyCode;
 } else { // mozilla
 keycode = e.which;
 }
 if(keycode == 27){ // close
 tb_remove();
 } else if(keycode == 190){ // display previous image
 if(!(TB_NextHTML == "")){
 document.onkeydown = "";
 goNext();
 }
 } else if(keycode == 188){ // display next image
 if(!(TB_PrevHTML == "")){
 document.onkeydown = "";
 goPrev();
 }
 } 
 };
 
 tb_position();
 $j("#TB_load").remove();
 $j("#TB_ImageOff").click(tb_remove);
 $j("#TB_window").css({display:"block"}); //for safari using css instead of show
 };
 
 imgPreloader.src = url;
 }else{//code to show html
 
 var queryString = url.replace(/^[^\?]+\??/,'');
 var params = tb_parseQuery( queryString );

 TB_WIDTH = (params['width']*1) + 60 || 630; //defaults to 630 if no paramaters were added to URL
 TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
 ajaxContentW = TB_WIDTH - 60;
 ajaxContentH = TB_HEIGHT - 45;
 
 if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window 
 urlNoQuery = url.split('TB_');
 $j("#TB_iframeContent").remove();
 if(params['modal'] != "true"){//iframe no modal
 $j("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
 }else{//iframe modal
 $j("#TB_overlay").unbind();
 $j("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
 }
 }else{// not an iframe, ajax
 if($j("#TB_window").css("display") != "block"){
 if(params['modal'] != "true"){//ajax no modal
 $j("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
 }else{//ajax modal
 $j("#TB_overlay").unbind();
 $j("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>"); 
 }
 }else{//this means the window is already up, we are just loading new content via ajax
 $j("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
 $j("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
 $j("#TB_ajaxContent")[0].scrollTop = 0;
 $j("#TB_ajaxWindowTitle").html(caption);
 }
 }
 
 $j("#TB_closeWindowButton").click(tb_remove);
 
 if(url.indexOf('TB_inline') != -1){ 
 $j("#TB_ajaxContent").append($j('#' + params['inlineId']).children());
 $j("#TB_window").unload(function () {
 $j('#' + params['inlineId']).append( $j("#TB_ajaxContent").children() ); // move elements back when you're finished
 });
 tb_position();
 $j("#TB_load").remove();
 $j("#TB_window").css({display:"block"}); 
 }else if(url.indexOf('TB_iframe') != -1){
 tb_position();
 if($.browser.safari){//safari needs help because it will not fire iframe onload
 $j("#TB_load").remove();
 $j("#TB_window").css({display:"block"});
 }
 }else{
 $j("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
 tb_position();
 $j("#TB_load").remove();
 tb_init("#TB_ajaxContent a.thickbox");
 $j("#TB_window").css({display:"block"});
 });
 }
 
 }

 if(!params['modal']){
 document.onkeyup = function(e){ 
 if (e == null) { // ie
 keycode = event.keyCode;
 } else { // mozilla
 keycode = e.which;
 }
 if(keycode == 27){ // close
 tb_remove();
 } 
 };
 }
 
 } catch(e) {
 //nothing here
 }
}

//helper functions below
function tb_showIframe(){
 $j("#TB_load").remove();
 $j("#TB_window").css({display:"block"});
}

function tb_remove() {
 baseURL = document.getElementById("baseurlid").value;
 curURL = document.getElementById("cururlid").value;


if(curURL == (baseURL + '?showLogin=true') || curURL == (baseURL + '?showLogin=true&doCheckout=true')){
 parent.RedirectParent();
}
 $j("#TB_imageOff").unbind("click");
 $j("#TB_closeWindowButton").unbind("click");
 $j("#TB_window").fadeOut("fast",function(){$j('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
 $j("#TB_load").remove();
 if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
 $j("body","html").css({height: "auto", width: "auto"});
 $j("html").css("overflow","");
 }
 document.onkeydown = "";
 document.onkeyup = "";
 return false;
}

function tb_position() {
$j("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
 if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
 $j("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
 }
}

function tb_parseQuery ( query ) {
 var Params = {};
 if ( ! query ) {return Params;}// return empty object
 var Pairs = query.split(/[;&]/);
 for ( var i = 0; i < Pairs.length; i++ ) {
 var KeyVal = Pairs[i].split('=');
 if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
 var key = unescape( KeyVal[0] );
 var val = unescape( KeyVal[1] );
 val = val.replace(/\+/g, ' ');
 Params[key] = val;
 }
 return Params;
}

function tb_getPageSize(){
 var de = document.documentElement;
 var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
 var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
 arrayPageSize = [w,h];
 return arrayPageSize;
}

function tb_detectMacXFF() {
 var userAgent = navigator.userAgent.toLowerCase();
 if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
 return true;
 }
}


