if (top !== self) top.location.replace(self.location.href);

// SHADOWBOX BEGIN

//Shadowbox.init();

// SHADOWBOX END

$( function()
{
	// JS SUPPORT BEGIN

	//$('body').addClass('js');
	
	// JS SUPPORT END
	
	// TOGGLE BEGIN
	
	$('a.toggle').each( function()
	{
		if ( ! $(this).hasClass('hide'))
		{
			$(this).next().hide();
		} else
		{
			$(this).next().show();
		}
	});
	
	$('a.toggle').click( function()
	{
		$(this).toggleClass('hide');
		
		if ($(this).hasClass('hide'))
		{
			$(this).next().show();
		} else
		{
			$(this).next().hide();
		}
		
		return false;
	});
	
	// TOGGLE END
	
	// DESCRIPTION FOR IMAGES FROM TITLE ATTRIBUTE BEGIN
	
	$('a.frame-holder > img').each( function()
	{
		if ($(this).attr('title') != '')
		{
			title = $(this).attr('title');

			$(this).after
			(
				$('<span />').addClass('title-description').text(title)
			);
			
			if ($(this).hasClass('aligncenter') || $(this).parent('a.frame').hasClass('aligncenter'))
			{
				$(this).load( function()
				{
					$img = $(this);
					
					$(this).parent('a.frame').css
					({
						'width': $img.width()
					});
				});
			}
		}
	});
	
	$('.frame-holder > *').each( function()
	{
		if ($(this)[0].tagName.toLowerCase() != 'img' && $(this)[0].tagName.toLowerCase() != 'span')
		{
			$(this).parent('.frame-holder').width($(this).width());
		}
	});
	
	// DESCRIPTION FOR IMAGES FROM TITLE ATTRIBUTE END
	
	// SCROLL TOP BEGIN
	
	$('a[href=#header], .separator').click( function()
	{
		$('html,body').animate
		({
			'scrollTop': 0
		}, 300);
		
		return false;
	});
	
	// SCROLL TOP END
	
	// FORM VALIDATION BEGIN
	
	$(config.form_validate).blur( function()
	{
		var val = $(this).val();

		$(this).removeClass('valid');
			
		if (val == '' || val == $(this).data('placeholder'))
		{
			$(this).addClass('error');
		} else
		{
			if ($(this).attr('name') == 'email' || $(this).attr('id') == 'email' || $(this).hasClass('email'))
			{
				if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(val))
				{
					$(this).removeClass('error').addClass('valid');
				} else
				{
					$(this).addClass('error');
				}
			} else
			{
				$(this).removeClass('error').addClass('valid');
			}
		}
	});
	
	$('form').submit( function()
	{
		if ($(this).find('input.error, textarea.error').length > 0)
		{
			return false;
		}
	});

	// FORM VALIDATION END
	
	// FORM PLACEHOLDERS BEGIN
	
	$(config.input_placeholder).placeholder(config.placeholder);
		
	// FORM PLACEHOLDERS END
	
	// PIP BEGIN
	
	$('div.pip ul.images').each( function()
	{
		$(this).css('width', 'auto');
		$(this).css('margin-left', -($(this).width() / 2));
	});
	
	$('div.pip ul.images li').click( function()
	{
		var $this = $(this);

		var $pip = $(this).parents('div.pip');
		var $enlarged = $pip.children('div.enlarged');
		
		var $img = $enlarged.children('img');
		
		$img.imgload($this.children('a').attr('href'), { path: config.images_dir, use_parent: true });

		return false;
	});
	
	// PIP END

	
	// ROUNDABOUT BEGIN
	
	$('ul.roundabout').css
	({
		'margin': '0 auto',
		'display': 'block',
		'float': 'none',
		'width': '620px'
	});

	$('ul.roundabout li').css
	({
		'margin': 0,
		'overflow': 'hidden'
	});
	
	$('ul.roundabout li > a > img').css
	({
		'width': '100%',
		'height': '100%'
	});

	$('ul.roundabout').roundabout
	({
		minScale: 0.65,
		childSelector: 'li'
	});
	
	// ROUNDABOUT END
	
	// CUSTOM MENU BEGIN

	$('ul.menu-1 li:not(.current) ul').hide();

	$('ul.menu-1 li > a').click( function(e)
	{
		var $current = $(this).parent('li');
		var $siblings = $(this).parent('li').siblings();
	
		$current.addClass('current');
		$current.children('ul').slideDown(500);
		
		if ($siblings.find('ul:visible').length > 0)
		{
			$siblings.find('ul:visible').slideUp(500, function()
			{
				$(this).parent('li').removeClass('current');
			});
		} else
		{
			$siblings.removeClass('current');
		}
		
		$current.parents('li').each( function()
		{
			$(this).removeClass('current');
			$(this).children('ul').show();
		});
	
		if ($(e.target).next('ul').length > 0)
		{
			return false;
		}
	});
	// CUSTOM MENU END
	
});

// QUICKSAND AJAX SAMPLE BEGIN
var FILTER_SLUG = '';
var FILTER_ITEMS = [];
var FILTER_COUNTER = 0;

function setup_filter(element, url, callback)
{
	$('ul.filters').hover( function()
	{
		
	}, function()
	{
		var $filter = $(this).find('input[type=checkbox]:checked');
		var categories = [];

		$filter.each( function()
		{
			categories.push($(this).attr('name'));
		});
		
		if (categories.join(',') != FILTER_SLUG && categories.join(',') != '')
		{
			FILTER_SLUG = categories.join(',');
			FILTER_ITEMS = [];
			FILTER_COUNTER = 0;
			
			$.each(categories, function(i, category)
			{
				$.get(url + '/' + category + '.html', function(data)
				{
					FILTER_ITEMS = $.merge(FILTER_ITEMS, $(data).children('li'));
					FILTER_COUNTER++;
					
					if (FILTER_COUNTER == FILTER_SLUG.split(',').length)
					{
						$(element).quicksand(FILTER_ITEMS, { adjustHeight: 'dynamic', enhancement: callback });
					}
				});
			});
		}
	});
}

function setup_pagination(element, dest, url, callback)
{
	$(element).click( function()
	{
		$.get(url + '.html', function(data)
		{
			var $items = $(data).children('li');
			
			$items.each( function()
			{
				$(this).attr('data-id', 'a' + Math.floor(Math.random() * 10000));
			});

			$(dest).quicksand($items.slice(0, $(dest).children('li').length), { adjustHeight: 'dynamic', enhancement: callback });
		});
		
		return false;
	});
}
// QUICKSAND AJAX SAMPLE END

