/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


var lightboxOpen = false;

var mouseOverButton = false;
var mouseOverList = false;

var timeTillCloseTrackList = 300; // In Miliseconds

// ------------------------------------------------------------------------------------

$(document).ready(function() {
    $('#websiteByBKA').css('top', $(window).height() - 35 + 'px').fadeIn(2000);
    //page background image
    placeBGImage()
    $(window).resize(function() {
        $('#facebookLink').css('top', $(this).height() - 30 + 'px');
        $('#websiteByBKA').css('top', $(this).height() - 35 + 'px');
        placeBGImage();
    });

    //TrackList functionality
    $('#trackList span').click(function() {
        return false;
    });
    $('#trackList span').mouseenter(function() {
        mouseOverButton = true;
        $('#trackList ul').show();
        return false;
    });
    $('#trackList span').mouseleave(function() {
        mouseOverButton = false;
        triggerListClose();
        return false;
    });
    $('#trackList ul').mouseenter(function() {
        mouseOverList = true;
        return false;
    });
    $('#trackList ul').mouseleave(function() {
        mouseOverList = false;
        triggerListClose();
        return false;
    });



    $('#trackList a').click(function() {
        $('#playing').text('PLAYING: ' + $(this).text());
        $('#trackList ul').hide();

        var clickedTrack = parseInt($(this).context.id.replace(/track_/, ""));
        thisMovie("mp3player").playTrackJS(clickedTrack);
        return false;
    });

    //Lightbox for menu items
    $('#primaryNav a.main,  label.cbConditions span a').click(function() {
        if ($(this).attr("href").indexOf("http://") > -1)
        {
            window.location = this.href;
        }
        else
        {
            _buildLightbox();
            loadContent(this.href);
            return false;
        }
    });

});

// ------------------------------------------------------------------------------------

function loadContent(url) {
    $('#lightboxLoadTarget').html('<iframe src="' + url + '" border="0" frameborder="0" ALLOWTRANSPARENCY="true" width="840px" height="900px" style="background:transparent;" />');
};

// ------------------------------------------------------------------------------------

function triggerListClose() {
    setTimeout("closeTrackList()", timeTillCloseTrackList);
}

// ------------------------------------------------------------------------------------

function closeTrackList() {
    if (mouseOverButton == false && mouseOverList == false) {
        $('#trackList ul').hide();
    }
}

// ------------------------------------------------------------------------------------
function placeBGImage()
{
	var imageAspectRatio = 1500/924;
	var windowAspectRatio = $(this).width()/$(this).height();
	
	if (imageAspectRatio > windowAspectRatio)
		$('#flashBackgroundInner img').css('height', '100%').css('width', 'auto');
	else
		$('#flashBackgroundInner img').css('height', 'auto').css('width', '100%');
}

// ------------------------------------------------------------------------------------
function _buildLightbox() {

    if (!lightboxOpen) {
        lightboxOpen = true;
    
        $('body').append('<div id="lightboxOverlay"></div>');
        $('body').append('<div id="lightboxContentWrap" style="left:0px;"><div id="lightboxContent"><a class="close" href="">Close</a><div id="lightboxLoadTarget"></div></div></div>');
        $('#lightboxContent a.close').supersleight();

        $('#lightboxOverlay').click(function() {
            _destroyLightbox();
            return false;
        });
        $('#lightboxContentWrap').click(function() {
            _destroyLightbox();
            return false;
        });
        $('#lightboxContent').click(function() {
            return false;
        });
        $('#lightboxContent a.close').click(function() {
            _destroyLightbox();
            return false;
        });
    }
};

// ------------------------------------------------------------------------------------
function _destroyLightbox() {
	$('#lightboxOverlay').remove();
	$('#lightboxContentWrap').remove();

	lightboxOpen = false;
	
	vidGalleryClose();
};

// ------------------------------------------------------------------------------------
function goToIdOnReady(id) {
    $(document).ready(function(){    
        var target = $('#' + id)
        target = target.size() && target;
        if (target.size()) {
            var targetOffset = target.offset().top;
            $('html').animate({ scrollTop: targetOffset }, 0);
        };
    });
};
// ------------------------------------------------------------------------------------
function goToId(id) {
    var target = $('#' + id)
    target = target.size() && target;
    if (target.size()) {
        var targetOffset = target.offset().top;
        $('html').animate({ scrollTop: targetOffset }, 0);
    };
};
// ------------------------------------------------------------------------------------
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1){
        return document.getElementById(movieName);//window[movieName];
    }
    else{
        return document[movieName];
    }
}
// ------------------------------------------------------------------------------------
function fromPlayer(track){
    var trackID = "#track_" + track;

    $('#playing').text('PLAYING: ' + $(trackID).text());       
}
// ------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------
// ------------------------  PLAY AND PAUSE WHEN IN VID -------------------------------
// ------------------------------------------------------------------------------------

var VidGalleryState = 0; // 0=closed, 1=open  -  This is used when pausing background movie and audio when in the vid gallery

function vidGalleryOpen() {
    VidGalleryState = 1;
 	thisMovie("flashBackgroundOuter").pauseVideo();
 	thisMovie("mp3player").pauseMP3();
    //alert('Vid Open');

}

function vidGalleryClose() {
    if (VidGalleryState == 1) {
        VidGalleryState = 0;
		
	 thisMovie("flashBackgroundOuter").resumeVideo();
	 thisMovie("mp3player").resumeMP3();
       // alert('Vid Closed');
    }
}

$(document).ready(function() {
    // checkout payment
    $('#paymentoption1').show();
    $('.inputRadio1').click(function(event) {
        $('#paymentoption1').show();
        $('#paymentoption2').hide();
        $('#paymentoption3').hide();
    });
    $('.inputRadio2').click(function(event) {
        $('#paymentoption1').hide();
        $('#paymentoption2').hide();
        $('#paymentoption3').show();
    });		
});

$(window).load(function() {
    $('.shopQty').mouseover(function() {
        $(this).css('color', '#666');
    });
    $('.shopQty').mouseout(function() {
        $(this).css('color', '#000');
    });
    $('.shopQty').click(function() {
        if ($(this).val() == 'Quantity')
            $(this).val('');
    });
    $('.shopQty').blur(function() {
        if ($(this).val() == '')
            $(this).val('Quantity');
    });
});
	
	function toggleCart(){
				$('.cartObj').slideToggle('slow', function() {
					   		if($('.b-Cart').text() == 'View Cart'){
								$('.b-Cart').text('Hide Cart');
						  	} else {
								$('.b-Cart').text('View Cart');
						  	}
					});
				}
				    
$(document).ready(function(){
//--------------------------------------------------------------------------------------
// cart function
//--------------------------------------------------------------------------------------
				//open and close the cart
				$('.b-Cart').mousedown(function() {
					 $('.cartObj').slideToggle('slow', function() {
					   		if($('.b-Cart').text() == 'View Cart'){
								$('.b-Cart').text('Hide Cart');
								//$('.b-Checkout').hide();
						  	} else {
								$('.b-Cart').text('View Cart');
								//$('.b-Checkout').show();								
						  	}
					});
				});		
				// remove an item
				$('.b-remove').mousedown(function(){
					$(this).parent().parent().fadeOut(function(){
							$(this).delay(500).remove();															   
					 });							  
				});
				$('.productObj').hover(function(){
							$(this).find('span.hover').slideDown('fast');	
							return false;														   
				}, function(){
							$(this).find('span.hover').slideUp('fast');															   
							return false;
				});
});
