/**
 * PShelper.com
 * Base Store Version javascript
 *
 * Notes:
 *
 * When creating text box inputs, always apply both
 * a value and default attribute (the same value)
 *
 * For rollovers use attribute 'hoversrc' to define the
 * rollover image source
 *
 **/
$(document).ready(function(){

/**
 * Tab Handling
 */
$('div.featuredTab:first').addClass('activeTab');
$('div.featuredSection').hide().filter(':first').show();
$('div.featuredTab').click(function(){
    clickedTab = $(this).attr('id');
    //hide all the panels and show the one clicked
    $('div.featuredSection').hide().filter('[rel="'+clickedTab+'"]').show();
    $('div.featuredTab').removeClass('activeTab');
    $(this).addClass('activeTab');
});

/**
 * INPUT TYPE=TEXT HANDLING
 */

	//input textbox handling
	$('input[type="text"]').focus(function(){
        if($(this).val()==$(this).attr('alt'))
        {
            $(this).val('');
        }
    }).blur(function(){
        if($(this).val()=='')
        {
            $(this).val($(this).attr('alt'));
        }
    });

/**
 * BASE TEMPLATE TOP NAVIGATION HANDLING
 */
    $('ul.parent li').hover(
        //mouse over
        function(){
           $(this).css({'zIndex':9999}).addClass('catOn').find('ul.sub').slideDown('fast');
        },
        //mouse out
        function(){
           $(this).removeClass('catOn').find('ul.sub').slideUp('fast'); 
        }).each(function(){
            $(this).find('ul.sub').hide();
        });
/**
 * ROLLOVER IMAGE HANDLING
 */
     //rollover image handling
     $preload = new Array();
     $iterator = 0;
     xOffset = 10;
	 yOffset = 20;

     $('img').each(function(){
        //preloader
        if($(this).attr('hoversrc'))
        {
            $preload[$iterator] = $('<img src="'+$(this).attr('hoversrc')+'"/>');
            $iterator++;

            $(this).hover(
            //mouse over
            function(){
                $(this).attr({'default':$(this).attr('src'),'src':$(this).attr('hoversrc')});
            },
            //mouse out
            function(){
                $(this).attr({'src':$(this).attr('default')});
                $(this).removeAttr('default');
            });
        }

        //preloader
        if($(this).attr('popsrc'))
        {
            $preload[$iterator] = $('<img src="'+$(this).attr('popsrc')+'"/>');
            $iterator++;

            $(this).hover(
            //mouse over
            function(e){
                $("body").append("<div id='imagepop'><img src='"+$(this).attr('popsrc')+"'/></div>");
                $("#imagepop")
                    .css({"top":(e.pageY - xOffset) + "px","left":(e.pageX + yOffset) + "px",'border':'2px solid #000000','position':'absolute'})
                    .show();
            },
            //mouse out
            function(){
                $("#imagepop").remove();
            })

            $(this).mousemove(function(e){
                $("#imagepop").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
            });
        }
     });
/**
*  jQuery Accordion
**/
	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();

});
