var SOP = {
    hideTitle: function(event) {
        if(this.value == $(this).attr('title')) $(this).attr('value', '').removeClass('default');
    },
    restoreTitle: function(event) {
        if(this.value.match(/^\s*$/)) $(this).attr('value', $(this).attr('title')).addClass('default').attr('autocomplete', 'off');
    }
};

$(document).ready(function() {
    
    // setup default text
    $('.default_text').focus(SOP.hideTitle).blur(SOP.restoreTitle).trigger('blur');
    $('button.subscribe_submit').click(function() {
        var input = $(this).prev('span.subscribe_textfield').children('input');
        if (input.attr('title') == input.attr('value')) {
            input.attr('value', '');
        }
    });

    if(typeof(setupZoom) === 'function') setupZoom();
    $('span.buycontent a').hover(function(event) {
        $(this).children('img[src*=zoom]').attr('src', 'art/store3/zoomh.jpg');
    }, function(event) {
        $(this).children('img[src*=zoom]').attr('src', 'art/store3/zoom.jpg');        
    });
       
    $('span.buycontent a').click(function(event) {
        this.blur();
    });

    $('#randomImage').attr('src', 'art/homeimage' + (Math.floor(Math.random() * 4) + 1) + '.jpg');
        
    $('.hover a').hover(function(event) {
        if ($.browser.msie) {
            $(this).children('img').css({filter: 'alpha(opacity=60)'});
        } else {
            $(this).children('img').css({opacity: '.6'});            
        }
    }, function(event) {
        if ($.browser.msie) {
            $(this).children('img').css({filter: 'alpha(opacity=100)'});
        } else {
            $(this).children('img').css({opacity: '1'});            
        }
    }).css('background', 'transparent');
    
    $('.clothing .buycontent').append($('<select name="síze" style="margin-top:10px; font-size: 14px">').append($('<option>Small</option><option>Medium</option><option>Large</option><option>Extra Large</option>')));
    $('.buycontent').append('<br /><input class="button" style="margin-top: 5px; background: url(art/buy_button.jpg) 0 -36px; width: 56px; height: 36px; border:0; text-indent: -9999px; cursor: pointer" />');
    $('.buycontent input.button').hover(function(){
        $(this).css({background: "url(art/buy_button.jpg) 0 0"});
    }, function() {
        $(this).css({background: "url(art/buy_button.jpg) 0 -36px"});
    });
    
    $('.buycontent input').click(function(event) {
        
        var f, name, price, size, format;
        name = $(this).prevAll('.name').text();
        price = $(this).prevAll('.price').text();
        size = $(this).prevAll('select').attr('value');
        format = $(this).prevAll('.format').text();
        
        f = $('<form />');
        f.attr({action: 'https://www.paypal.com/cgi-bin/webscr', method: 'post', style: 'position: absolute; height: 1px; width: 1px; top: 0; left: 0; overflow: hidden', target: 'sopStore'});
        f.append($('<input />').attr({name: 'business', value: 'chris@someoddpilot.com'}));
        f.append($('<input />').attr({name: 'cmd', value: '_cart'}));
        f.append($('<input />').attr({name: 'add', value: '1'}));
        f.append($('<input />').attr({name: 'item_name', value: name}));
        f.append($('<input />').attr({name: 'amount', value: price}));
        f.append($('<input />').attr({name: 'currency_code', value: 'USD'}));
        f.append($('<input />').attr({name: 'undefined_quantity', value: '1'}));
        if (size) {
            f.append($('<input />').attr({name:'on0', value: 'Size'}));
            f.append($('<input />').attr({name: 'os0', value: size}));
        }
        if (format) {
            f.append($('<input />').attr({name:'on0', value: 'Format'}));
            f.append($('<input />').attr({name: 'os0', value: format}));
        }
        f.append($('<input />').attr({name: 'no_shipping', value: '2'}));

        $('body').append(f);
        f.submit();
    });
    
});

$(window).load(function () {
    if(typeof AC_FL_RunContent == 'function') {
        $('#homePageFlashHolder').html(AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','930','height','407','src','home7d','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','home7d'));  
    } 
});
