(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(',');for(var i=0;i<e.length;i++){document.createElement(e[i])}})()

if(String(window.location).search("brinkdev.com") == -1)
	var base_url = "/sheba";
else
	var base_url = "";
var feature_index = 1;
var features_array = new Array();

$(document).ready(function(){
	$("#feature-image").css('display','none');
	$("#navigation li:not(.current)").css( {backgroundPosition: "0px -100px", backgroundImage:"url("+base_url+"/media/images/common/navHighlight-trans.png)"})
	$("#navigation li:not(.current)").mouseover(function(){ $(this).stop().animate( {backgroundPosition:"0px 0px"},250)})
	$("#navigation li:not(.current)").mouseout(function(){ $(this).stop().animate( {backgroundPosition:"0px -100px"},250)})
				
});

function getFeatures(page)
{
	$("#feature-box").css('display','none');
	$("#feature-box-bg").css('display','none');
	$.post(base_url + '/ajax/features/'+page,{},function(data,textStatus)
		 {
			 $.each(data.images, function(i,item)
				  {
					  img = new Image(990,290);
					  img.src = item;
				  	  features_array.push(img);
				  });
			 $("#feature-box").fadeIn('fast');
			 $("#feature-box-bg").fadeIn('fast');
			 $("#feature-image").html(features_array[0]);
			 $("#feature-image img").load(function() { $('#feature-image').fadeIn('slow'); });
			 if(data.images.length > 1)
			 	setInterval('loadFeatureImage()',15000);
		 },"json");
}

function loadFeatureImage()
{
	$("#feature-image").css('display','none');
	$("#feature-image").html(features_array[feature_index]);
	$("#feature-image").fadeIn('slow');
	if(feature_index == features_array.length -1)
		feature_index = 0;
	else
		feature_index++;
}

$(function(){

	$("ul.dropdown li").hover(function(){
	
		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');
	
	}, function(){
	
			$(this).removeClass("hover");
			$('ul:first',this).css('visibility', 'hidden');   
	});
	

	
	$("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

});

function addToCart(type, id, div)
{
	$.post('/cart/addToCart', { type:type, id:id }, function(data){
		$("#" + div).html(data);
		$("#" + div).fadeIn("slow");
		setTimeout(function(){
			$("#" + div).fadeOut("slow");
		}, 3000);
	});
}

function removeItem(id)
{
	$.post('/cart/removeItem', { id:id }, function(data){
		window.location = '/cart/viewCart';
	});
}

function numbersOnly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;

	else if ((("0123456789").indexOf(keychar) > -1))
		return true;

	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}



function showLargerPress(url)
{
	var n = url.split('press/').join('press/originals/');
	$('#press_view_large').html('<a href="javascript:hideLargePress();"><img src="' + n + '" alt="" /></a>');
	$('#press_view_large').fadeIn("slow");
}

function hideLargePress()
{
	$('#press_view_large').fadeOut("slow");
}

function hoverSwap( image, newImg ) {
	old = image.src;
	image.src = newImg;
	image.onmouseout = function(){ image.src = old; };
}

function updateCart()
{
	document.getElementById('cart_items').submit();
}

function viewMore(id)
{
	var c = $('#more_content' + id).css('display');

	if(c == 'none')
		$('#more_content' + id).css('display', 'block');
	else
		$('#more_content' + id).css('display', 'none');
}

function addNewsletter()
{
	var email = $('#nletter').val();

	$('#nlSuccess').html("Success! Thank you for subscribing!");

	$('#nlSuccess').fadeIn("medium", function(){
		setTimeout(function(){
			$('#nlSuccess').fadeOut("medium");
			$('#nlSuccess').html('');
		}, 3000);	
	});

	nlt();
}

function nlt()
{
	$.post('/home/nlSignup',{email:email},function(data)
	 {


	 },"json");
}

$(document).ready(function(){

	// This is the dropdown menu handling

	$("ul.topnav li a").hover(function() { 

		$(this).parent().find("ul.subnav").slideDown('fast').show(); 

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('fast'); 
		});
	});

	$("ul.subnav li a").hover(function() {

		$(this).parent().find("ul").slideDown('fast').show(); 

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul").slideUp('fast');
		});

	});

});

