window.addEvent('domready', function(){
    var select_tags = $$('select');
    exterior_selector = select_tags[0];
    interior_selector = select_tags[1];
    handle_selector = select_tags[2];
    if(select_tags[3]){ribbon_selector = select_tags[3];}

    // get the url params, if there are any.
    var exterior_choice=get_url_param('exterior_choice').replace(/swatch-/, "");
    var handle_choice=get_url_param('handle_choice').replace(/swatch-/, "");
    var interior_choice=get_url_param('interior_choice').replace(/swatch-/, "");
    var ribbon_choice=get_url_param('ribbon_choice').replace(/swatch-/, "");
    if(exterior_choice)
    {
        exterior_selector.value=exterior_choice;
        interior_selector.value=interior_choice;
        if(handle_selector){handle_selector.value=handle_choice;}

        toggle_element('exterior', exterior_choice);
        toggle_element('handle', handle_choice);
        toggle_element('interior', interior_choice);
    }
    if(ribbon_choice && ribbon_selector)
    {
        ribbon_selector.value=ribbon_choice;
        toggle_element('ribbon', ribbon_choice);
    }
});

function is_array( mixed_var ) {
    return ( mixed_var instanceof Array );
}
function get_url_param(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
        {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
            {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}
function open_configurator()
{
    //currently not using this function.  This was an attempt to pass parameters to the iframe.
    var select_tags = $$('select');
    var exterior_selector = select_tags[0];
    var interior_selector = select_tags[1];
    var handle_selector = select_tags[2];
    if(select_tags[3]){ribbon_selector=select_tags[3];}
    
    TB_show('hiih', 'http://sassybb.edopod.net/index.php?keepThis=false&amp;TB_iframe=true&amp;height=400&amp;width=700&amp;name=product_configurator&amp;exterior_choice=2&amp;happiness=yay', 'exterior_choice=hello');
}
function this_starts_the_purse_configurator(product_id,config)
{
    if(is_array(config)==false)
    {
        var top = config;
        var config = Array();
        config['exterior_top']=top+'px';
        config['interior_top']=top+'px';
        config['ribbon_top']=top+'px';
    }
    if(config['handle_top']==null){config['handle_top']='0';}
    if(config['exterior_top']==null){config['exterior_top']='0';}
    if(config['interior_top']==null){config['interior_top']='0';}
    if(config['handle_left']==null){config['handle_left']='center';}
    if(config['interior_left']==null){config['interior_left']='center';}
    if(config['exterior_left']==null){config['exterior_left']='center';}
    if(config['ribbon_left']==null){config['ribbon_left']='center';}
    document.write('<input type="hidden" value="'+product_id+'" id="product_id" name="product_id" />');
    document.write('<style>');
    document.write('#the-exterior{background-image:url(http://sassybb.edopod.net/components/'+product_id+'/exterior-0.gif);background-position:'+config['exterior_left']+' '+config['exterior_top']+';background-size:30% auto;}');
    document.write('#the-interior{background-image:url(http://sassybb.edopod.net/components/'+product_id+'/interior-0.gif);background-position:'+config['interior_left']+' '+config['interior_top']+';}');
    document.write('#the-handle{background-image:url(http://sassybb.edopod.net/components/'+product_id+'/handle-0.gif);background-position:'+config['handle_left']+' '+config['handle_top']+';}');
    document.write('#the-ribbon{background-image:url(http://sassybb.edopod.net/components/'+product_id+'/ribbon-0.gif);background-position:'+config['ribbon_left']+' '+config['ribbon_top']+';}');
    document.write('</style>');
    document.write('<div id="purse-div">');
    document.write('<div id="interior-div"><img id="the-interior" src="http://sassybb.edopod.net/images/spacer.gif" width="230" height="300" /></div>');
    document.write('<div id="handle-div"><img   id="the-handle"   src="http://sassybb.edopod.net/images/spacer.gif" width="230" height="300" /></div>');
    document.write('<div id="exterior-div"><img id="the-exterior" src="http://sassybb.edopod.net/images/spacer.gif" width="230" height="300" /></div>');
    document.write('<div id="ribbon-div"><img id="the-ribbon" src="http://sassybb.edopod.net/images/spacer.gif" width="230" height="300" /></div>');
    document.write('</div>');    
    document.write('<img src="http://sassybb.edopod.net/images/customize-button-hover.gif" style="display:none;" />');
    document.write('<a href="http://sassybb.edopod.net/index.php?product_id='+product_id+'&amp;&amp;height=400&amp;width=700&amp;name=product_configurator&amp;exterior_top='+config['exterior_top']+'&amp;interior_top='+config['interior_top']+'&amp;handle_top='+config['handle_top']+'&amp;exterior_left='+config['exterior_left']+'&amp;interior_left='+config['interior_left']+'&amp;handle_left='+config['handle_left']+'&amp;ribbon_top='+config['ribbon_top']+'&amp;ribbon_left='+config['ribbon_left']+'&amp;keepThis=true&amp;TB_iframe=true&amp;happiness=yay"');
    document.write('title="Customize Your SassyBB Purse" class="smoothbox"><img id="customize-button" src="http://sassybb.edopod.net/images/spacer.gif" width="125" height="30" /></a>');
    if(config['handle_on_top']==true)
    {
      document.write('<style>#handle-div{z-index:100;}</style>');
    }
}