/**
 * 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('default'))
        {
            $(this).val('');
        }
    }).blur(function(){
        if($(this).val()=='')
        {
            $(this).val($(this).attr('default'));
        }
    });

/**
 * 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");
            });
        }
     });
});