
$(function(){
   $('a').live('hover', function(){
      var href = $(this).attr('href');
   
      if(/http/.test(href)){
         
         if(/cos247.com/.test(href) == true){
            
            if(/wp-admin/.test(href) == true){
               
               $(this).addClass('external');
               
            }else{
               
               $(this).addClass('internal');
               
            }
         }else{
            
            $(this).addClass('external');
            
         }
         
         
      }else{
         
         $(this).addClass('internal');
         
      }
      
      $('.external').live('click', function(){
         $(this).attr('target', '_blank');
      });
   
      $('.internal').live('click', function(){
         
         var x = $(this).attr('class'),
             url = $(this).attr('href'),
             n = $(this).attr('name'),
             l = "<center><img src='http://cos247.com/images/loading.gif' alt='loading' /></center>",
             s = 150,
             o = "div#mainContent",
             b = "div#backToStoreSlide",
             a = "div#sliderWrapper",
             h = {width: '396px',opacity: 0.7,height: '123px'},
             f = {width: '435px', opacity: 1.0, height: '135px'},
             q = {opacity: 0.7},
             c = " #loader";
             
         if ($(c, this).length === 0) {
            //$('#waterMark').css('background-image', 'url(http://cos247.com/images/waterMark.gif)');
         }
         
               
         
         if(/navigation/.test(x)){
            
            $(b).fadeOut(s);
            $(a).slideDown(s);
            $(o).empty().html(l);
            $(o).load(url + c, function(){
               $('.vaultImg').each(function(){
                  var $t = $(this);
                  $t.animate(q,s);
                  $t.hover(function () {$t.animate({opacity: 1},s);}, function () {$t.animate(q,s);});
               });
               $(".tnImg").each( function(){
                  var $t = $(this);
                  $t.animate(h,s);
                  $t.hover(function () {$t.animate(f,s);}, function () {$t.animate(h,s);});
               });	
            });
            
         }else if(/navFilter/.test(x)){
            
            $(b).fadeOut(s);
            $(a).slideDown(s);
            $(o).empty().html(l);
            $(o).load(url + ' ' + n, function(){
               $('.headFilter').show();
               $(".tnImg").each( function(){
                  var $t = $(this);
                  $t.animate(h,s);
                  $t.hover(function () {$t.animate(f,s);}, function () {$t.animate(h,s);});
               });
            });
            
         }else if(/pro/.test(x)){
            
            $(b).fadeIn(s);
            $(a).slideUp(s);
            $(o).empty().html(l);
            $(o).load(url+ c, function(){
               $('a[rel*=lightbox]').lightBox();
               if($('input[name=item_name]').attr('value') == 'Soulful Commando Collab'){
                  $('option[value=medium]').remove();
                  $('option[value=large]').remove();
                  $('option[value=xlarge]').remove();
                  function updateOptions(){
                  }
                  
                  
                  $('select[name=os1]').change(updateOptions);
                  updateOptions();
               
               }else if($('input[name=item_name]').attr('value') == 'Born to Win'){
               
                  function updateOptionsBTW(){
                     
                     if($('select[name=os1]').attr('value') == 'yellow'){
                        
                        if(!$('option[value=large]').length){
                         
                           $('option[value=xlarge]').before('<option value="medium">medium</option><option value="large">large</option>');  
                           
                        }
                        
                     }
                        
                     if($('select[name=os1]').attr('value') == 'blue'){
                        
                        $('option[value=medium]').remove();
                        $('option[value=large]').remove();

                        
                     }
                     
                  }
                  
                  
                  $('select[name=os1]').change(updateOptionsBTW);
                  updateOptionsBTW();
                  
               }else if($('input[name=item_name]').attr('value') == 'COS Inc.'){
               
                  function updateOptionsINC(){
                     
                     if($('select[name=os1]').attr('value') == 'blue'){
                        
                        if(!$('option[value=xxlarge]').length){
                         
                           $('option[value=xlarge]').after('<option value="xxlarge">xxlarge</option>');  
                           
                        }
                        
                     }
                        
                     if($('select[name=os1]').attr('value') == 'orange'){
                        
                        $('option[value=xxlarge]').remove();

                        
                     }
                     
                  }
                  
                  
                  $('select[name=os1]').change(updateOptionsINC);
                  updateOptionsINC();
               } 
               
            });


            
         }else{
            
            $(o).load(url + c);
            
         }
         
         return false;
      });

          
   });
     
   $('.hoverEffect').children('div').hover(function(){
      $(this).children('a').animate({fontSize: "20px"}, 200);
      $(this).parent('div').siblings('.dropDown').children('ul').children('li').hide().slideDown("slow");
   }, function(){
      $(this).children('a').animate({fontSize: "18px"}, 200);   
   });
   
  
  $('.dropDown li ul').parent().each(function(){
      $(this).css('background-image', 'url(http://cos247.com/images/more.png)');
   });
  
});
   
