$(document).ready(function(){
	$('div.brand_frame, div.brand_frame_return').hover(fadeMouseOver, fadeMouseOut);
	$('div.product_frame, div.product_frame_return').hover(fadeMouseOver, fadeMouseOut);
	$('a.connection_link').hover(fadeMouseOver, fadeMouseOut);
	$('p.view_all a').hover(fadeMouseOver, fadeMouseOut);
	$('a.event_image img').hover(fadeMouseOver, fadeMouseOut);
	function fadeMouseOver ()
	{
		$(this).fadeTo(200, .65);
	}
	function fadeMouseOut ()
	{
		$(this).fadeTo(200, 1);
	}
	$('div.brand_frame, div.brand_frame_return, div.product_frame, div.product_frame_return').click(function(){
		window.location = $(this).find('a').attr('href');
		return false;
	});
	$('#body').logo();
	$('#brand_title').radius('brand_title');
	$('.brand_event').radius('brand_event');
	$('.product_thumbnail').radius('product_thumbnail');
	$('#product_image').radius('product_image');

	var i = 0;
	$('#thumbnail_selected').empty();
	for (;;)
	{
		if ($('#product_thumbnail' + i).size() > 0)
		{
			makeThumbnail(i);
			i ++;
		}
		else
		{
			break;
		}
	}
	function makeThumbnail (i)
	{
		$('#product_thumbnail' + i).hover(
			function(){
				$('#product_image img').empty();
				$('#product_image').append(makeURL($('#product_thumbnail' + i).attr('src')));
				$('#thumbnail_selected').css('marginTop', 0);
				$('#thumbnail_selected').css('marginLeft', i * 145);
			}
		);
	}
	function makeURL(u)
	{
		var str = u.split('/');
		str.pop();
		var url = str.join('/');
		return '<img src="' + url + '.jpg" width="703" height="393" />';
	}
});

(function($)
{
	$.fn.logo = function()
	{
		var _this = this;
		this.init = function()
		{
			var url = '/get/brand_logo/';
			$.getJSON(url, function(data){
				_this.getLogoJSON(data);
			});
		}
		this.getLogoJSON = function(d)
		{
			var n = d.name;
			var p = d.path;
			for (var i = 0; i < n.length; i ++)
			{
				var c = {
					display: 'block',
					background: 'url(' + p[i] + ') center center no-repeat'
				}
				$('h3.brand_logo > a#title_' + n[i]).css(c);
			}
		}
		_this.init();
	};
})(jQuery);

