$(function(){
    $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
    /********SCROLL PANE********/
    if (jQuery().jScrollPane)
    {    
        $('.scroll_pane').jScrollPane();
    }


    /********LIGHTBOX CONTROLS********/
    $('.heidi_photos').click(function()
    {
        $.openDOMWindow({
            loaderImagePath: 'img/loader.gif',
            loader: 1,
            loaderHeight: 16,
            loaderWidth: 16,
            windowSourceID: '#heidis_photos',
            height: 635
        });
        return false;
    });
    $('.access_hollywood').click(function()
    {
        $.openDOMWindow({
            loaderImagePath: 'img/loader.gif',
            loader: 1,
            loaderHeight: 16,
            loaderWidth: 16,
            windowSourceID: '#access_hollywood',
            height: 635
        });
        return false;
    });
    $('.commercials').click(function()
    {
        $.openDOMWindow({
            loaderImagePath: 'img/loader.gif',
            loader: 1,
            loaderHeight: 16,
            loaderWidth: 16,
            windowSourceID: '#commercials',
            height: 635
        });
        return false;
    });
	$('.beachhouse_commercial a').click(function()
    {
        $.openDOMWindow({
            loaderImagePath: 'img/loader.gif',
            loader: 1,
            loaderHeight: 16,
            loaderWidth: 16,
            windowSourceID: '#beachhouse_video',
            height: 635
        });
        return false;
    });

    $('.lightbox_close').click(function(){	
        $.closeDOMWindow();
		$('#DOMWindow').hide();
    });
    /****Arrow Clicking****/
    $('.heidis_photos .arrow_left').click(function()
    {
        if ($('.heidis_photos ul.photo_selector li.selected').is(':first-child'))
        {
            //Get's the source and replaces it
            var source = $('.heidis_photos ul.photo_selector li:last-child img').attr('src');
            source = source.replace('_small', '_big');
            $('.heidis_photos .photo img').attr({ src: source });
            //Changes the selected li
            $('.heidis_photos ul.photo_selector li.selected').removeClass('selected');
            $('.heidis_photos ul.photo_selector li:last-child').addClass('selected');
            $('.heidis_photos ul.photo_selector li img').fadeTo('fast', 1);
            $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
        } else
        {
            //Get's the source and replaces it
            var source = $('.heidis_photos ul.photo_selector li.selected').prev().children().attr('src');
            source = source.replace('_small', '_big');
            $('.heidis_photos .photo img').attr({ src: source });
            //Changes the selected li
            $('.heidis_photos ul.photo_selector li.selected').removeClass('selected').prev().addClass('selected');
            $('.heidis_photos ul.photo_selector li img').fadeTo('fast', 1);
            $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
        }
        return false;
    });
    $('.heidis_photos .arrow_right').click(function()
    {
        //if this isn't the last photo
        if ($('.heidis_photos ul.photo_selector li.selected').is(':last-child'))
        {
            //Get's the source and replaces it
            var source = $('.heidis_photos ul.photo_selector li:first-child img').attr('src');
            source = source.replace('_small', '_big');
            $('.heidis_photos .photo img').attr({ src: source });
            //Changes the selected li
            $('.heidis_photos ul.photo_selector li.selected').removeClass('selected');
            $('.heidis_photos ul.photo_selector li:first-child').addClass('selected');
            $('.heidis_photos ul.photo_selector li img').fadeTo('fast', 1);
            $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
        } else
        {
            //Get's the source and replaces it
            var source = $('.heidis_photos ul.photo_selector li.selected').next().children().attr('src');
            source = source.replace('_small', '_big');
            $('.heidis_photos .photo img').attr({ src: source });
            //Changes the selected li
            $('.heidis_photos ul.photo_selector li.selected').removeClass('selected').next().addClass('selected');
            $('.heidis_photos ul.photo_selector li img').fadeTo('fast', 1);
            $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
        }
        return false;
    });

    /****Photo Thumbnail****/
    $('.heidis_photos ul.photo_selector li img').click(function()
    {
        var source = $(this).attr('src');
        source = source.replace('_small', '_big');
        $('.heidis_photos .photo').fadeOut('fast', function()
        {
            $('.heidis_photos .photo img').attr({ src: source });
            $('.heidis_photos .photo').fadeIn();
        });
        $('.heidis_photos ul.photo_selector li.selected').removeClass('selected');
        $(this).parent().addClass('selected');
        $('.heidis_photos ul.photo_selector li img').fadeTo('fast', 1);
        $('.heidis_photos ul.photo_selector li.selected img').fadeTo('fast', .5);
    });

    /****Product Linking****/
    var hrefattr = $('#product_list li.active a').attr('href');
    var product_class = $('#body').attr('class');
    $('#product_list ul a').click(function()
    {
        hrefattr = $(this).attr('href');
        product_class = $('#body').attr('class');
        $('#product_list ul li').removeClass('active');
        $(this).parent().addClass('active');
        $('#product_photo').fadeOut(function()
        {
            $('#product_photo').css('background-image', 'url(img/product_img/' + product_class + '/' + hrefattr.substring(1) + '.jpg)');
            $('#product_photo').fadeIn();
        });
        return false;
    });

    /****Nutritionals****/
    $('.nutritional_info').click(function()
    {
        $('#nutritional_image').css('background-image', 'url(img/nutritionals/' + product_class + '/' + hrefattr.substring(1) + '.jpg)');
        $.openDOMWindow({
            windowSourceID: '#nutritionals',
            height: 800,
            loaderImagePath: 'img/loader.gif',
            loader: 1,
            loaderHeight: 16,
            loaderWidth: 16
        });
        return false;
    });
});

function form_complete() {
    $(function(){
	    $.openDOMWindow({
		    loaderImagePath:'img/loader.gif',
		    loader:1,
		    loaderHeight:16,
		    loaderWidth:16,
		    windowSourceID:'#thank_you',
		    height:400
	    });
	    return false;
	});
}
