/* Copyright 2010-2012 Lucht Studios, LLC http://LuchtStudios.com */
var _ie6OrLess=false;

jQuery.noConflict();
jQuery(document).ready(function() {
    jQuery(".jHover").mouseenter(function() {
        swapImage(jQuery(this).get(0));
    }).mouseleave(function() {
        swapImage(jQuery(this).get(0));
    }).focus(function() {
        swapImage(jQuery(this).get(0));
    }).blur(function() {
        swapImage(jQuery(this).get(0));
    }).each(function(i, element) {
        /* preload background image */
        jQuery('<img />').get(0).src = element.src.replace('.png', '_Hover.png');
    });

    if (_ie6OrLess) {
        fixIE6PNG();
    };

    if (jQuery('body.faqs').length > 0) {
        faqRearrange();
    }

    try {
		if (window.location.toString().indexOf('showall=1') > 0) {
			jQuery('#banner').addClass('jsShowAll');
			jQuery('img', jQuery('#banner')).each(function() {
			   jQuery(this).attr('title', jQuery(this).attr('src'));
	        });
		} else {
	        bannerSlideshow.init();
		}
    } catch (e) { }

    function swapImage(image) {
        if (image.src.substring(image.src.length - '_Hover.png'.length) == '_Hover.png') {
            image.src = image.src.replace('_Hover', '');
        } else {
            image.src = image.src.replace('.png', '_Hover.png');
        }
    }

    try {
        initializeCalendar();
    } catch (e) { }
});

function fixIE6PNG() {
    var sPath = 'assetsV3/';
    if (window.location.toString().indexOf('artist-template-website-samples') > 0) {
      sPath = '../../assetsV3/';
    } else if (window.location.toString().indexOf('artist-website-plans') > 0) {
      sPath = '../assetsV3/';
    }
      
    jQuery('.png').each(function(i, element) {
	    jQuery(element).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + element.src + '", sizingMethod="scale")')
		    .css('width', jQuery(element).width() + 'px')
		    .css('height', jQuery(element).height() + 'px')
		    .css('background-image', 'none');

	    element.src = sPath + 'spacer.gif';
    });
}
function accordionInit() {
	jQuery("#accordion").accordion({
		autoHeight: false,
		navigation: true, 
		change: function(event, ui) {
			var sUrl;
			try {
				sUrl = 'http://luchtstudios.com/il/il.aspx?f=accordion&t=' + encodeURI(jQuery(ui.newHeader).text().replace(/[^a-z0-9]/gi, ''));
				jQuery.ajax({url:sUrl});
			} catch(e) {}
		}
	});
	
}

function faqRearrange() {
    var sClass;
    var sClassInline;
    var index = 0;

    jQuery('#faqDetails').css('padding-top', '8em');
    jQuery('#faqDetails').css('padding-bottom', '6em');
    jQuery('#faqDetails .category').each(function(i, element) {
        sClass = jQuery(element).attr('class');
        sClassInline = '.' + sClass.replace(' ', '.');
        jQuery('#faqSummary').append('<div class="' + sClass + '"></div>');
        jQuery(element).find('h2').each(function(i, e2) {
            jQuery('#faqSummary ' + sClassInline).append('<h2>' + jQuery(e2).text() + '</h2>');

            jQuery(element).find('h3').each(function(i, e3) {
                jQuery(e3).before('<a name="faq' + index + '"></a>');
                jQuery('#faqSummary ' + sClassInline).append('<a href="#faq' + index + '">' + jQuery(e3).text() + '</a>');
                index++;
            });

        });
    });
}  //faqRearrange

var bannerSlideshow = {
    currentIndex: 0,
    banners: null,
    fadeTime: 1000,
    messageTime: 700,
    holdTime: 5000,
    init: function () {
        var oMessage;

        if (jQuery('#banner').length > 0) {
            bannerSlideshow.banners = jQuery('.bannerWrap');
            bannerSlideshow.banners.each(function (index, element) {
                oMessage = jQuery('.bannerMessage', jQuery(this));
                oMessage.data('topEnd', oMessage.position().top);

                if (oMessage.data().topEnd > (jQuery(this).height() / 2)) {
                    oMessage.data('topStart', jQuery(this).height() - oMessage.height());
                } else {
                    oMessage.data('topStart', 0);
                }

                oMessage.css({ top: oMessage.data('topStart') });
            });

            jQuery('.bannerMessage').css({ visibility: 'visible' }).hide();
            jQuery('#banner').addClass('jsRunning');

            setTimeout(function() {bannerSlideshow.holdCurrent();}, 1700);
        }
    },
    holdCurrent: function () {
        bannerSlideshow.showMessage();
        setTimeout(bannerSlideshow.gotoNext, bannerSlideshow.holdTime);
    },
    gotoNext: function () {
        bannerSlideshow.hideCurrent();
        setTimeout(bannerSlideshow.showNext, bannerSlideshow.fadeTime * 0.8);
    },
    hideCurrent: function () {
        var iThis = bannerSlideshow.currentIndex;
        var oBanner = bannerSlideshow.banners.eq(iThis);

        setTimeout(function () { bannerSlideshow.hideCurrentMessage(oBanner) }, bannerSlideshow.fadeTime * .1);
        oBanner.css({ opacity: 1 }).animate({ opacity: 0 }, bannerSlideshow.fadeTime);
    },
    hideCurrentMessage: function (banner) {
        jQuery('.bannerMessage', banner).hide();
    },
    showNext: function () {
        bannerSlideshow.currentIndex++;
        if (bannerSlideshow.currentIndex >= bannerSlideshow.banners.length) {
            bannerSlideshow.currentIndex = 0;
        }
        var oBanner = bannerSlideshow.banners.eq(bannerSlideshow.currentIndex);

        oBanner.css({ opacity: 0 }).show().animate({ opacity: 1 }, bannerSlideshow.fadeTime, function () {
            bannerSlideshow.holdCurrent();
        });
    },
    showMessage: function () {
        var oMessage = jQuery('.bannerMessage', bannerSlideshow.banners.eq(bannerSlideshow.currentIndex));
        oMessage
            .css({ top: oMessage.data().topStart, visibility: 'visible' })
            .show()
            .animate({ top: oMessage.data().topEnd }, bannerSlideshow.messageTime);
    }
} //bannerSlideshow   



