// JavaScript Document

// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = false; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD

//ONLOAD MANAGER
function womOn(){
  window.onload = womGo;
}

function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}

function womAdd(func){
  woms[woms.length] = func;
}

function CreateBookmarkLink() {

	title = document.title;
	url = window.location.href;
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if(window.external) {
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) {
		return true;
	}
	
}

function objToggle(obj) { 

	var obj = document.getElementById(obj);

	if(obj.style.display == "block") { 
		obj.style.display = "none";
	} else { 
		obj.style.display = "block";
	}

}

function drop_down_menu() {
	
	
	
}

function toggle() {

	if(!document.getElementsByTagName('div')) return false;
	
	var links = $('a.toggle');
	
	hideNews(links);
	
	links.click(function() {
	
		var href = this.getAttribute('href');
		var bits = href.split('#');
		var element_id = bits[1];
		
		var div = $('#'+element_id);
		
		if(div.is(':hidden')) {
		
			 div.show("slow");
		
		} else {
		
			div.slideUp();
		
		}
		
		return false;
	
	});

}

function hideNews(links) {

	for(var i=0; i<links.length; i++) {
	
		var href = links[i].getAttribute('href');
		var bits = href.split('#');
		var element_id = bits[1];
		var div = $('#'+element_id);
		
		div.addClass('hidden');
	
	}

}

function skypeLink() {

	if($('a.skypeLink').length == 0) return false;
	
	var skypeLink = $('a.skypeLink');
	
	skypeLink.click(function() {
		
		 return skypeCheck();
	
	});

}

function highlightInputValue() {

	if(!document.getElementsByTagName('input')) return false; //MAKE SURE THERE ARE INPUTS TO HIGHLIGHT
									  
	var inputs = document.getElementsByTagName('input'); //GET INPUOTS
	
	for(var i=0; i<inputs.length; i++) { //LOOP THROUGH ELEMENTS
		
		inputs[i].onfocus = function() { //ELEMENT IS FOCUS
			
			this.select(); //SELECT VALUE
		
		}
	
	}

}

var featured_prod;
var curritem=0;

//Animates the featured products on the homepage
function homePageAnim() {

    featured_prod = $("#featured_product div").fadeOut('slow').size();
    $("#featured_product div:eq("+curritem+")").fadeIn('slow');
    setInterval(ticknews,8000); //time in milliseconds
	
}

function ticknews() {
    $("#featured_product div:eq("+curritem+")").fadeOut('slow');
    curritem = ++curritem%featured_prod;
    $("#featured_product div:eq("+curritem+")").fadeIn('slow');

}

function carousel() {

	if($('.mycarousel').length == 0) return false;
	
	jQuery('.mycarousel').jcarousel();

}

//Make all product cells on a page the same height
function gridHeight() {

	if($('.product').length == 0) return false;
	
	var productCells = $('.product');
	var maxHeight = 0;
	
	for(var i=0; i<productCells.length; i++) {
	
		var cellHeight = productCells[i].offsetHeight;
	
		if(cellHeight > maxHeight) {
		
			maxHeight = cellHeight;
		
		}
	
	}
	
	for(var i=0; i<productCells.length; i++) {
	
		$(productCells[i]).css('height', maxHeight + 'px');
	
	}
	

}

function dropDown() {

	if($('#top_nav').length == 0) return false;
	
	$('#top_nav li').mouseover(function () {
	
		if($(this).children().length > 1) {
	
			$('#top_nav li ul').addClass('over');
		
		}
	
	});
	
	$('#top_nav li').mouseout(function () {
	
		$('#top_nav li ul').removeClass('over');
	
	});

}

function tabs() {

	//if($('#product_list').length == 0) return false;
	//alert('here');
	var $tabs = $("#product_list").tabs();
	
}

$(document).ready(function() {

	toggle();
	homePageAnim();
	//tabs();
	carousel();
	gridHeight();
	skypeLink();
	dropDown();
	
	if(navigator.userAgent.indexOf('MSIE 6') < 0) {
		tabs();	
	}
	
	//drop_down_menu();

});
