﻿//*******************************************/
// Created by:   Get Started Pty Ltd
//               http://www.getstarted.com.au/
// Author(s):    Brett Walsh
// Last updated: 25 Jun 2010
//*******************************************/


// lightbox (colorbox)
function initLightBox() {
    if ($('a').hasClass('color-box')) { $(".color-box").colorbox(); }
}

function initProducts() {

    // if there is only one, show it
    if ($('.faqs dd').size() == 1) {
        $(this).show();
    }

    // toggle product summary
    $('.faqs dd').hide();
    $('.faqs dt').hover(function () { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); }).click(function () {
        var $Previous = $('.faqs dt.active');
        var $Current = $(this);
        if (!$Current.hasClass("active")) {
            $Current.next().slideToggle('normal');
            $Current.addClass("active");
        }
        $Previous.removeClass("active").next().slideToggle('normal');
    });

    $('.product-summary').click(function() {

        // show "resources" for selected product
        $('div#resources').fadeIn(500);
        $('.resource').hide();
        $('#res-' + this.id + '').stop(true, true).fadeIn(500);

        // show "also known as" for selected product
        $('div#aka').fadeIn(500);
        $('.alsoknownas').hide();
        $('.aka-' + this.id + '').stop(true,true).fadeIn(500);

        // show "similar to" for selected product
        $('div#similar').fadeIn(500);
        $('.similarto').hide();
        $('.simto-' + this.id + '').stop(true, true).fadeIn(500);

        // show product properties

        $('.products-table').fadeIn(500);
        $('.product-properties').hide();
        $('.prop-' + this.id + '').stop(true, true).fadeIn(500);
        
    });

}

function initGetQuoteForm() {
    $('.form .btn-add-request').click(function () {
        //Make it visible
        var NewAdditional = $('.additional-hidden:first');
        NewAdditional.removeClass('additional-hidden');
        NewAdditional.addClass('additional-show');
        if ($('.additional-hidden').length === 0) {
            $(this).hide();
        }
        
    });
}

function initIndex() {
	$('#az-index').listnav({
	includeAll: true,
	includeNums: true,
	includeOther: false,
	flagDisabled: false,
	noMatchText: '<li><strong>No matching entries</strong><li>', 
	showCounts: false, 
	prefixes: ['the','a']
    });
}

function initFlowPlayer() {
    var $player = $("flowplayer", "/assets/flowplayer/flowplayer-3.1.5.swf", {
    });
    $("img[rel]").overlay({ effect: 'apple',
        onLoad: function() { 
            $player.load(); 
        },
        onClose: function () {
            $player.unload();
        }
    });
}

function compareProducts() {
    $(document).ready(function() {
        var products = [];
        $(".compare-check:checked").each(function() { products.push(this.value); });
        products = jQuery.unique(products);
        
        if (products.length > 0) {
            window.location.href = 'compare-results?prodIds=' + products;
        } else {
            alert('Please select some products to compare');
        }
    });
}

function initFixedTable() {
    var t = $('.fixedTableDiv');
    var tWidth = 700;
    var tHeight = t.outerHeight(true) + 50;
    $('.fixedTableDiv').css({ 'width': tWidth, 'height': tHeight });
    $('.fixedTableDiv').fixedHeaderTable({ autoResize: false, fixCol1: true });
}

function initSearchValidation() {

    $('#search .button').click(function() {

        if ($('#search .textfield').val().length <= 0) {
            alert('Please enter a search term');
            return false;
        }

    });

}

// colorbox function
function cb(e, strClass) {
	$(strClass).css('display','block');
    $.fn.colorbox({ inline: true, href: strClass, onClosed: function() { $(strClass).css('display', 'none'); } }); 
}

$(document).ready(function() {

    initLightBox();

    initProducts();

    initGetQuoteForm();

    //initIndex();

    initFlowPlayer();

    initSearchValidation();
	
	initBizFormDropDowns();
});
