$(document).ready(function(){

	if (!document.getElementById) return
		var imgOriginSrc;
		var imgTemp = new Array();
		var imgarr = document.getElementsByTagName('img');
		for (var i = 0; i < imgarr.length; i++) {
			if (imgarr[i].getAttribute('hsrc')) {
				imgTemp[i] = new Image();
				imgTemp[i].src = imgarr[i].getAttribute('hsrc');
				imgarr[i].onmouseover = function() {
				imgOriginSrc = this.getAttribute('src');
				this.setAttribute('src',this.getAttribute('hsrc'))
			}
			imgarr[i].onmouseout = function() {
				this.setAttribute('src',imgOriginSrc)
			}
		}
	}
	
	$("div.onlinestoreContainer:eq(0)").css({display: "block"});
	var currentContainer = $(".onlinestoreContainer:eq(0)");
	var currentTab = $(".onlinestore_tabs li:eq(0)");
	
	$('.onlinestore_tabs #tabs ul').children().each(function() {
		
		$(this).click( function() {
			
			var tab = $(this).find("a").attr("href");
			var temp = tab.lastIndexOf('#');
			tab = tab.substring(temp+1);
			
			$(currentTab).removeClass("active");
			$(this).addClass("active");
			currentTab = $(this);
			
			$(currentContainer).hide();
			currentContainer = $("//a[@name='"+tab+"']").parent();
			$(currentContainer).show();
			
			return false;
		} );

	});
	
	// ------------------------------------------------------------ //
	// online store sliders, click expand button panel opens, click again panel closes
	function setupSliders() {
		// loop each of the sliders and attach the toggle function to open and close content
		$('.slider').each(function(i){
			var open = $(this).parent().attr('id');
			if (open != "slider_open") {
				//var myslider = $(this); // normal slider
				$(this).toggle(function() {
					$(this).parent().find('.slider_content').css("border-bottom","1px solid #bfc2c3").slideDown('300');
					$(this).parent().find('.slider_control img').attr("src", "images/btn_close.gif");
					$(this).parent().find('.slider').addClass('slider_on');
					
				}, function() {
					$(this).parent().find('.slider_content').slideUp('fast', function() {
						$(this).css("border-bottom","none")
					});
					$(this).parent().find('.slider_control img').attr("src", "images/btn_expand.gif");
					$(this).parent().find('.slider').removeClass('slider_on');
				});	
			}
			
				
		});
		
	}
	setupSliders();
	
	// if a slider has an id assigned as #slider_open this code slides the panel open
	if ($('#slider_open')) {
		$('#slider_open .slider_control img').attr("src", "images/btn_close.gif");
		$('#slider_open .slider_content').css("border-bottom","1px solid #bfc2c3").slideDown('300');
		$('#slider_open .slider').addClass('slider_on');
		$('#slider_open .slider').toggle(function() {
			$(this).parent().find('.slider_content').slideUp('fast', function() {
					$(this).css("border-bottom","none")
			});
			$(this).parent().find('.slider_control img').attr("src", "images/btn_expand.gif");
			$(this).parent().find('.slider').removeClass('slider_on');					 
		}, function() {
				$(this).parent().find('.slider_content').css("border-bottom","1px solid #bfc2c3").slideDown('300');
				$(this).parent().find('.slider_control img').attr("src", "images/btn_close.gif");
				$(this).parent().find('.slider').addClass('slider_on');
		})								 
	}

});

function mypopup(pUrl,w,h)
{
	mywindow = window.open (pUrl,'mywindow','location=0,status=0,scrollbars=1,width='+w+',height='+h+'');
}
