﻿if (window.innerHeight)  {
	var myHeight = window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight) { 
	var myHeight = document.documentElement.clientHeight;
} 
else if (document.body) {
	var myHeight = document.body.clientHeight;
} 

window.addEvent('domready', function(){
    var heightAdjust = (myHeight - 153);
    var heightAdjustIE = (myHeight - 374);
    var myWindowHeight = window.getHeight();
    var myScrollHeight = window.getScrollHeight();
    var myUserAgent = navigator.userAgent;
    var browserIE7 = myUserAgent.match('MSIE 7');
    var browserIE6 = myUserAgent.match('MSIE 6');
    if (myScrollHeight == myWindowHeight) {
        if (browserIE6 || browserIE7) {
            $$('div.height-adjust').set('style', 'height: ' + heightAdjustIE + 'px;');
        }
        else{$$('div.height-adjust').set('style', 'height: ' + heightAdjust + 'px;');}
    }
    var mastCart = $('mast-cart');
    Cufon.replace(mastCart);
    $$('div.nav ul li.shows').addEvents({
        'mouseenter': function(){
            this.getElement('.rollover').addClass('active');
            this.getElement('ul').setStyle('display', 'block');
        },
        'mouseleave': function(){
            this.getElement('.rollover').removeClass('active');
            this.getElement('ul').setStyle('display', 'none');
        }
    });
    var positionElements = $$('div.position-elements');
    positionElements.inject('main-div', 'top');
    var addBg = $$('div.add-bg');
    addBg.inject($(document.body), 'top');
    if (browserIE6) {}
    else {
        $$('div.content div.home-video img').addEvent('click', function(){this.fade(0);});
        $$('div.gu-video-gallery img').addEvent('click', function(){
            if (this.hasClass('video-mucca-pazza')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="mucca-pazza">Mucca Pazza</h3><object width="370" height="294"><param name="movie" value="http://www.youtube.com/v/CqHnPUJQ2fw&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CqHnPUJQ2fw&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="370" height="294"></embed></object>');
            }
            else if (this.hasClass('video-los-de')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="los-de-abajo">Los De Abajo</h3><object width="370" height="290"><param name="allowFullScreen" value="true"/><param name="wmode" value="transparent"/><param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m=43388446,t=1,mt=video"/><embed src="http://mediaservices.myspace.com/services/media/embed.aspx/m=43388446,t=1,mt=video" width="370" height="290" allowFullScreen="true" type="application/x-shockwave-flash" wmode="transparent"></embed></object>');
            }
            else if (this.hasClass('video-watcha')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="watcha-clan">Watcha Clan</h3><object width="370" height="294"><param name="movie" value="http://www.youtube.com/v/gwSSUaZdihs&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/gwSSUaZdihs&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="370" height="294"></embed></object>');
            }
            else if (this.hasClass('video-red-baraat')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="red-baraat">Red Baraat</h3><object width="370" height="294"><param name="movie" value="http://www.youtube.com/v/A-uM-pULeQg&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/A-uM-pULeQg&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="370" height="294"></embed></object>');
            }
            else if (this.hasClass('video-hanggai')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="hanggai">Hanggai</h3><object width="370" height="294"><param name="movie" value="http://www.youtube.com/v/eyarB9rS5Is&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/eyarB9rS5Is&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="370" height="294"></embed></object>');
            }
            else if (this.hasClass('video-minyeshu')) {
                $$('div.gu-video').set('html', '<h2 class="videos">Videos</h2><h3 class="minyeshu">Minyeshu</h3><object width="370" height="294"><param name="movie" value="http://www.youtube.com/v/250jVmjyyt0&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/250jVmjyyt0&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="370" height="294"></embed></object>');
            }
        });
        $$('div.video-chooser a').addEvent('click', function(e) {
            e.preventDefault();
            var href = this.getProperty('href');
            var v = href.split('=');
            var youtube = 'http://www.youtube.com/v/' + v[1];
            $$('div.video').set('html', '<object width="425" height="344"><param name="movie" value="' + youtube + '" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed src="' + youtube + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344" /></object>');

        });
    }
    $$('.delete-item').setStyle('visibility', 'hidden');
    $$('table.cart tr.item-information').addEvents({
        'mouseenter': function(){
            this.getElement('.delete-item').setStyle('visibility', 'visible'); 
        },
        'mouseleave': function(){
            this.getElement('.delete-item').setStyle('visibility', 'hidden');
        }
    });
    function formatCurrency(num) {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
            num = "0";
            sign = (num == (num = Math.abs(num)));
            num = Math.floor(num*100+0.50000000001);
            cents = num%100;
            num = Math.floor(num/100).toString();
            
            if(cents<10)
                cents = "0" + cents;
                for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                    num = num.substring(0,num.length-(4*i+3))+','+
                    num.substring(num.length-(4*i+3));
                    return (((sign)?'':'-') + '$' + num + '.' + cents);
                }
    var ticketPrice = $$('div.cart-block input[type=hidden]').getProperty('value');
    $$('div.cart-block span.total-price').set('text', formatCurrency(ticketPrice));
    $$('div.cart-block input.qty').addEvent('keyup', function(){
        var ticketQty = $$('div.cart-block input[type=text]').getProperty('value');
        $$('div.cart-block span.total-price').set('text', formatCurrency(ticketQty * ticketPrice));
    });
    $$('.event').each(function(apEvent) {
        var eventPrice = apEvent.getElement('input[type=hidden]');
        var eventPriceValue = eventPrice.getProperty('value');
        var eventTotalPrice = apEvent.getElement('.total-price');
        eventTotalPrice.set('text', formatCurrency(eventPriceValue));
        apEvent.getElement('input.qty').addEvent('keyup', function(){
            var eventQty = apEvent.getElement('input[type=text]');
            var eventQtyValue = eventQty.getProperty('value');
            eventTotalPrice.set('text', formatCurrency(eventQtyValue * eventPriceValue));
        });
    });
    $$('div.event:last-child').setStyle('border', 0);
    
    $$('div.checkout a.cvv').addEvents({
        'click': function(e){
            e.preventDefault(); 
        },
        'mouseenter': function(){
            $$('div.content div.checkout div.cards img.cvv').setStyle('display', 'block'); 
        },
        'mouseleave': function(){
            $$('div.content div.checkout div.cards img.cvv').setStyle('display', 'none'); 
        }
    });
    var pullDown = new Fx.Morph('mailing-list', {
        duration: 500,
        transition: Fx.Transitions.Quint.easeOut,
        wait: false
    });
    $$('div.mailing-list').addEvents({
        'click': function(){
            pullDown.start({
                'height': 148,
                'top': -156
            });
        },
        'mouseleave': function(){
            pullDown.start({
                'height': 18,
                'top': -28
            });
        }
    });
});