
var swatches                = new Array();
var swatch_prices           = new Array();
var total_options_price     = 0;
var option_prices           = new Array();
var current_option_prices   = new Array();
var available_selections    = new Array();
var product_price;
var total_price;
var msie                    = false;


var hive_product = {
	init: function() {
	
        jQuery.each(jQuery.browser, function(i, val) {
            if (i == 'msie' && val) {
                msie = true;
            }
        });

        preloadImages('/images/basic_arrow_down.gif');
        preloadImages('/images/basic_arrow_up.gif');
        
        $(".product_page_header").hover(
            function () {
                //$('.search_links').fadeIn();
            }, 
            function () {
                $('.search_links').fadeOut();
            }
        );

        $('#product_slideshow').cycle({
            fx: 'fade',
            speed: 3000,
            timeout: 8000
        });

        $('.cl_1').click(function() {
            if ($(this).next().css('display') != 'block') {
                $('.cl_1').next().hide('slow');
                $('.cl_2').next().hide('slow');
                $('.cl_3').next().hide('slow');
                $(this).next().toggle('slow');
		    }
		    $('.cl_2').removeClass('cat_on');
		    $('.cl_1').removeClass('cat_on');
		    $(this).addClass('cat_on');
		    return false;
	    });

	    $('.cl_2').click(function() {
		    $('.cl_2').removeClass('cat_on');
		    $('.cl').removeClass('cat_on');
	        if ($(this).next().css('display') != 'block') {
                $('.cl_2').next().hide('slow');
                $('.cl_3').next().hide('slow');
                $(this).next().toggle('slow');
		    }
            
		    $(this).addClass('cat_on');
		    return false;
	    });

	    $('.cl_3').click(function() {
		    if ($(this).next().css('display') != 'block') {
                $(this).parent().parent().find('.cat_sub').hide('slow');
		        $(this).next().toggle('slow');
		    } else {
		        $(this).next().toggle('slow');
		    }
		    $('.cl_3').css('color','#808080');
		    $('.cl_4').css('color','#808080');
		    $(this).css('color','#FCAF17');
		    return false;
	    });

        $('.cl_4').click(function() {
		    if ($(this).next().css('display') != 'block') {
                $(this).parent().parent().parent().find('.cat_sub').hide('slow');
		        $(this).next().toggle('slow');
		    }
		     else {
		        $(this).next().toggle('slow');
		    }
		    $('.cl_4').css('color','#808080');
		    $(this).css('color','#FCAF17');
		    return false;
	    });
        
        var myFile = document.location.toString();
        if (myFile.match('#')) { // the URL contains an anchor
            // click the navigation item corresponding to the anchor
            var myAnchor = '#'+myFile.split('#')[1];
        }
        
        
        $('.cat_sub').hide();


        $(".product_thumb").each(
            function () {
            $(this).attr('alt', '');
                $(this).qtip({
                    content: {
                        url: '/ajax/product_rollovers_left.html',
                        data: { sub_product_id: $(this).parent().attr('rel') },
                        method: 'get'
                    },
                    position: {
                        corner: {
                            target: 'rightMiddle',
                            tooltip: 'leftMiddle'
                        }
                    },
                    style: { 
                        width: 200,
                        height: 105,
                        padding: 8,
                        background: '#FFFFFF',
                        color: '808080',
                        textAlign: 'left',
                        border: {
                            width: 0,
                            color: '#FFFFFF'
                        }
                    }
                });
            }
        );
    
        $(".product_thumb_left").each(
            function () {
            $(this).attr('alt', '');
                $(this).qtip({
                    content: {
                        url: '/ajax/product_rollovers_right.html',
                        data: { sub_product_id: $(this).parent().attr('rel') },
                        method: 'get'
                    },
                    position: {
                        corner: {
                            target: 'leftMiddle',
                            tooltip: 'rightMiddle'
                        }
                    },
                    style: { 
                        width: 200,
                        height: 115,
                        padding: 5,
                        background: '#FFFFFF',
                        color: '808080',
                        textAlign: 'right',
                        border: {
                            width: 0,
                            color: '#FFFFFF'
                        }
                    }
                });
            }
        );

	}
}

jQuery(document).ready(function() {
	hive_product.init();
});


function change_product(sub_product_id) {
    location.href = "/pages/products.php?view=sub_product&sid="+sub_product_id;
}

function load_products(category_id) {
    $("#product_space").fadeOut(200,
        function() {
            $("#product_space").css("background", "#FFFFFF url('"+"/images/hive_animation.gif') no-repeat 0 0");
            $("#product_space").load("/ajax/ajax.functions.php", { category_id: category_id,action: 'load_products' }, function() {
                $("#product_space").fadeIn(900);
            });
        }
    );
}

function load_sub_product(sub_product_id) {
    return false;
    $("#product_space").fadeOut(200,
        function() {
            $("#product_space").css("background", "#FFFFFF url('"+"/images/hive_animation.gif') no-repeat 0 0");
            $("#product_space").load("/ajax/ajax.functions.php", { sub_product_id: sub_product_id, action: 'load_sub_product' }, function() {
                $("#product_space").fadeIn(900);
            });
        }
    );
}

function back_to_sub_product() {
    $('#product_left_content_2').fadeOut();
    $('#product_left_content_1').fadeIn();
}

function back_to_swatches() {
    $('#product_left_content_1').fadeOut();
    $('#product_left_content_2').fadeIn();
}


function update_main_sub_photo(photo_src) {
    $('#product_left_content_2').fadeOut();
    $('#product_left_content_1').fadeIn();
    $('#mi').fadeOut(600, function () {
        $('#mi').attr('src', photo_src);
    }).fadeIn(700);
}

function load_swatches(swatch_index, sub_product_id, swatch_set_id) {
    $('#product_left_content_2').html('');
    $('#product_left_content_1').fadeOut();
    $('#product_left_content_2').fadeIn();
    $("#product_left_content_2").load("/ajax/ajax.functions.php", {swatch_index: swatch_index, sub_product_id: sub_product_id, swatch_set_id: swatch_set_id, action: 'get_swatches'}, function() {
    
    });
    
}

function update_swatch_prices() {
    swatch_price = 0;
    for (var i = 0; i < swatch_prices.length; i++) {
        swatch_price += parseInt(swatch_prices[i]);
    }
}

function swatch_choice_complete() {
    if (num_swatch_sets) {
        if (num_swatch_sets != swatches.length) {
            alert('Please complete your option choices by clicking on the swatch buttons.');
            return false;
        } else {
            return true;
        }
    }
}

function open_modal_dialog(warning) {
    var overlay = $(jQuery('<div id="modal_overlay" style="display: none"></div>'));
    var container = $(jQuery('<div id="modal_warning" style="display: none"></div>'));
    var logo = $(jQuery('<div style="padding:10px 0;"><img src="../images/hive-modern-furniture.gif" border="0" /></div>'));
    var close = $(jQuery('<div style="padding-top:10px;"><a href="javascript:;" class="close_button">Close</a></div>'));
    overlay.fadeTo(50, 0.5);
    container.append(logo);
    container.append(close);
    container.prepend(warning);
    $('body').append(overlay).append(container);
    container.show().css({'top': Math.round((($(window).height() > window.innerHeight ? window.innerHeight : $(window).height()) - container.outerHeight()) / 2) + 'px', 'left': Math.round(($(window).width() - container.outerWidth()) / 2) + 'px', 'margin-top': 0, 'margin-left': 0}).hide();
    overlay.add(container).fadeIn('normal');
    //container.corners(); // this renders a bug firefox PC
    close.click(function(c) {
        c.preventDefault();
        overlay.add(container).fadeOut('normal');
    });
    overlay.click(function(c) {
        c.preventDefault();
        overlay.add(container).fadeOut('normal');
    });
}





function set_choice_in_frame(image, swatch_name, price) {
    $('#swatch_choice_2').html('<img src="'+image+'" border="0" />');
    $('#swatch_description_local').html('current selection: '+swatch_name);
    if (price > 0) {
        $('#swatch_description_price').html('<span class="yellow">$'+price+' additonal</span>');
    } else {
        $('#swatch_description_price').html('');
    }
    $('#swatch_info_local').fadeIn(500);
}

function hover_swatch_info(swatch_line_id, name, price) {
    if (price > 0) {
        $('#swatch_info_'+swatch_line_id).html(name+' : $'+price+' additonal');
    } else {
        $('#swatch_info_'+swatch_line_id).html(name);
    }
}

function reset_swatch_info(swatch_line_id) {
    $('#swatch_info_'+swatch_line_id).html('');
}



