$(document).ready(function(){
    // Hide all accordion divs
	$(document).pngFix();
    $('.accordion-header').siblings("div").hide();
    // Active tab
	if(typeof activeTab != 'undefined'){
		if(typeof console != 'undefined'){
			console.log(activeTab);
		}
		$('#'+activeTab).show();
	}
	
    // Expand & contract link handlers
    $('#accordion-controller-link').click(function(){
        if($(this).hasClass("expanded")){
            $(this).removeClass("expanded").text("Expand All");
            $('.accordion-header').siblings('div').hide();
            $('a.accordion-header').removeClass('selected');
        } else {
            $(this).addClass("expanded").text("Collapse All");
            $('.accordion-header').siblings('div').slideDown();
            $('a.accordion-header').addClass('selected');
        }
    });

    // Handle accordion headers clicks
    $('.accordion-header').click(function() {
        //$(this).siblings("div").hide(); // hide all (default)
        $(this).siblings("a").removeClass("selected");
        var div = $(this).next("div");
        div.siblings("div").hide();
        div.slideToggle('fast');

        if(div.css('display') == 'block'){
            $(this).addClass("selected");
        }
        return false;
    });
				
    $('img.large-image').hide();
    $('img.pickBtn').each(function()
    {
        $(this).qtip(
        {
            content: {
                // Set the text to an image HTML string with the correct src URL to the loading image you want to use
                text: $(this).attr('title')
            },
            position: {
                corner: {
                    target: 'rightMiddle', // Position the tooltip above the link
                    tooltip: 'leftMiddle'
                },
                adjust: {
                    screen: false // Keep the tooltip on-screen at all times
                }
            },
            show: { 
                delay: 0,
                when: 'mouseover', 
                solo: true // Only show one tooltip at a time
            },
            hide: {
                when: 'mouseout',
                effect: 'fade'
            },
            style: {
                tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
                border: {
                    width: 0,
                    radius: 4
                },
                name: 'dark', // Use the default light style
                width: 150 // Set the tooltip width
            }
        })
    });




    $('div.tabs').tabs();
    var tabContainers = $('div.tabs > div');
    tabContainers.hide().filter(':hs-overview').show();
    $('div.tabs ul#overview-tabs a').click(function () {
        $(this).addClass('selected');
        return false;
    }).filter(':hs-overview').click();  
	
    // Basket focus on ready
    basketFocus();

// Create the modal backdrop on document load so all modal tooltips can use it
    $(document.createElement("div"))
    .css({
        position: 'absolute',
        top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
        left: 0,
        height: $(document).height(), // Span the full document height...
        width: '100%', // ...and full width

        opacity: 0.7, // Make it slightly transparent
        backgroundColor: 'black',
        zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
    })
    .attr("id","qtip-blanket")
    .appendTo(document.body) // Append to the document body
    .hide(); // Hide it initially
	
	// Hide the product info modal dialog
	$('#buynowContent').hide();
	$('#buynow').qtip({
                    content: {
                        title: {
                            text: $('#mobileName').val(),
                            button: 'Close x'
                        },
                        text: $('#buynowContent')
                    },
                    position: {
                        target: $(document.body), // Position it via the document body...
                        corner: 'center' // ...at the center of the viewport
                    },
                    show: {
                        when: 'click', // Show it on click
                        solo: true // And hide all other tooltips
                    },
                    hide: false,
                    style: {
                        width: 500,
                        height: 400,
                        padding: '14px',
                        border: {
                            width: 9,
                            radius: 9,
                            color: '#666666'
                        },
                        name: 'light'
                    },
                    api: {
                        beforeShow: function()
                        {
                            // Fade in the modal "blanket" using the defined show speed
                            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                        },
                        beforeHide: function()
                        {
                            // Fade out the modal "blanket" using the defined hide speed
                            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                        }
                    }
                });
$('#outofstock').qtip({
                    content: {
                        title: {
                            text: $('#mobileName').val(),
                            button: 'Close x'
                        },
                        text: $('#oos-form')
                    },
                    position: {
                        target: $(document.body), // Position it via the document body...
                        corner: 'center' // ...at the center of the viewport
                    },
                    show: {
                        when: 'click', // Show it on click
                        solo: true // And hide all other tooltips
                    },
                    hide: false,
                    style: {
                        width: 250,
                        height: 330,
                        padding: '14px',
                        border: {
                            width: 9,
                            radius: 9,
                            color: '#666666'
                        },
                        name: 'light'
                    },
                    api: {
                        beforeShow: function()
                        {
                            // Fade in the modal "blanket" using the defined show speed
                            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                        },
                        beforeHide: function()
                        {
                            // Fade out the modal "blanket" using the defined hide speed
                            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                        }
                    }
                });

                $('#trigger').qtip({
                    content: {
                        title: {
                            text: 'Callback Form',
                            button: 'Close x'
                        },
                        url: 'callback.html'
                    },
                    position: {
                        target: $(document.body), // Position it via the document body...
                        corner: 'center' // ...at the center of the viewport
                    },
                    show: {
                        when: 'click', // Show it on click
                        solo: true // And hide all other tooltips
                    },
                    hide: false,
                    style: {
                        width: 250,
                        height: 330,
                        padding: '14px',
                        border: {
                            width: 9,
                            radius: 9,
                            color: '#666666'
                        },
                        name: 'light'
                    },
                    api: {
                        beforeShow: function()
                        {
                            // Fade in the modal "blanket" using the defined show speed
                            $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                        },
                        beforeHide: function()
                        {
                            // Fade out the modal "blanket" using the defined hide speed
                            $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                        }
                    }
                });

});
function basketFocus(){
    $('div.purchase-details, div.purchase-details + a').slideUp("fast", function(){
        $(this).slideDown();
    });
	$('div.shopping_cart').pulsate();
}