$(document).ready(function(){

    $('h1').data('name', $('h1 em').text());
	
    $('#additionalImages div').click(function(){
        
        //$('h1 em').text($('h1 em').text().replace(' - collection', ''));
        $('h1 em').text($('h1').data('name'));

        $('#eneVideo').remove();
        
        //$('#bigImage').html("<div id='loadingSmall'>Loading...</div>");
        
        var parts = $(this).attr('id').split("-");
        //$('#bigImage').css('background', 'url(/images/content/products/' + parts[1] + '/l/' + parts[2] + '.jpg) no-repeat center center');
        
        //$('#bigImage').html('');
        $('#bigImage img').attr('src','');
        $('#bigImage img').attr('src', '/images/content/products/' + parts[1] + '/l/' + parts[2] + '.jpg');
        
        return false;
    });
    
    $('#groups div').click(function(){
    
        var text;
        
        $('#eneVideo').remove();
        
        //$('#bigImage').html("<div id='loadingSmall'>Loading...</div>");
        
        var parts = $(this).attr('id').split("-");
        //$('#bigImage').css('background', 'url(/images/content/products/' + parts[1] + '/l/' + parts[2] + '.jpg) no-repeat center center');
        
        //$('#bigImage').html('');
        $('#bigImage img').attr('src','');
        $('#bigImage img').attr('src', 'http://www.zenithinteriors.com.au/images/content/group-products/' + parts[1] + '/l/' + parts[2] + '.jpg');
        
        if (!$('h1 em').text().match(' - collection')) {
        
            var parts = this.id.split('-');
            var id = parts[1];
            var a = [2371,2372,2373];
            var b = [2258,2259,2260,2261,2262];
            a = oc(a);
            b = oc(b);
            if (id in a) {
                $('h1 em').text('Glass Collection');
            
            } else if (id in b) {
                $('h1 em').text('Ellis Collection');
            
            } else {
                text = $('h1').data('name').split(' ')[0];
                $('h1 em').text(text + ' collection');
            }
        }
        
        return false;
    });
    
    $('#videoLink').click(function(){
        $('#bigImage img').attr('src','');
        var html = "<a href='/media/products/ene.flv' id='eneVideo'></a>";
        $('#bigImage').append(html);
        flowplayer("eneVideo", "/media/flowplayer-3.1.1.swf");
        return false;
    });
    
});

function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}
