/**
 * File name:	sharedFunctions.js
 * Date:	10/13/2006
 * Author:	Brian Schemp
 * 
 * 	Purpose:	Includes functions that can be used by other scripts.
 * 
 * 
 * History:	11/02/2006 Brian - Added function changeHeaderImage().
 * 			11/22/2006 Brian - Added functions createHeaderImageCarlineElement(), createHeaderImageTimeOfDayElement() and createImageElement().
 * 			01/19/2007 Brian - Added function getEventSourceObject.
 *			01/08/2009 Brian - Added function onMouseDownEvent.
 */

//variables to determine the browser type
var ie4 = document.all;
var ns6 = document.getElementById&&!document.all;


$(function(){
	$.nyroModalSettings({
		type: "iframe",
		closeButton: false,
		windowResize: true,
		titleFromIframe: null,
		title: null,
		width: 610,
		height: 270,
		minWidth: 610,
		minHeight: 270
	});		   
});

/**
* Close the popup window by setting a onClick event for a
* html element.
*
*/
function popupClose(closeButtonObj){
	closeButtonObj.click(function(evt){
		evt.preventDefault();		 	 
	 	$.nyroModalRemove();					
	});	
}

/**
* Called when a pop-up is created. Sets the width and height.
*
*/
function popupInit(wrapElementHeight, specific_width){	
	var popup_body_height = wrapElementHeight + 10;
	var main_window_height = $(document).height();
	var specific_height = 0;
	
	//determine what height to use.
	if(popup_body_height < main_window_height){
		specific_height = popup_body_height;
	}else{
		specific_height = main_window_height;
	}
	
	//specific width and height for IE 6
	if($.browser.msie && $.browser.version == '6.0'){
		document.getElementById("nyroModalWrapper").style.width = (width+18)+"px";
		document.getElementById("nyroModalWrapper").style.overflow = "hidden";
		document.getElementById("nyroModalContent").style.width = (width+30)+"px";
		document.getElementById("nyroModalContent").style.position = "absolute";
		document.getElementById("nyroModalContent").style.top = "0px";
		document.getElementById("nyroModalContent").style.left = "-20px";
		
	//specific width and height for all other browsers.
	}else{
		$.nyroModalSettings({
			width: specific_width,
			height: specific_height,
			minWidth: specific_width,
			minHeight: specific_height
		});
	}
	
	//set pop-up background to not have an image.
	$("#nyroModalIframe").contents().find("body").css("background", "none");
}


/**
 * Purpose:	Check the value is a number
 * 
 * qty	the value to check.
 */ 
function validateProductQuantity(qty)
{
	var zeroRE = /^[0]+$/;
	
	if(qty.length == 0)
		return false;
	
	else if(qty.match(zeroRE))
		return false;
	
	else if(!(isNumeric(qty)))
		return false;
		
	else
		return true;
}

/**
* Get the url variables.
*
*/
function getUrlVars() {
	var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


/**
* Anonymous function to preload images
*
*/
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

/**
*	Change the image source for a specific image element.
*
* @param {Object} imageElement 
* @param {Object} imageName 
* @param {Object} imageDirectory 
*/
function swapImage(imageElement, imageName, imageDirectory){
	var fullImagePath = imageDirectory + imageName;
	
	imageElement.attr({
		src: fullImagePath
	});
}

/**
 * Purpose:	Checks if a user is logged in before adding a product to their wish list
*/
function checkUserLoginWishList()
{
	var customerIdCookieRE = /customerId/i;
	var cookieArray = document.cookie.split(';');http://www.classicindustries.com/
	var cookieFound = 0;
	
	for(var i=0;i < cookieArray.length;i++)
	{
		var cookieValue = cookieArray[i];
		if(cookieValue.match(customerIdCookieRE))
		{
			cookieFound = 1;
			break;
		}
	}
	
	if(cookieFound == 0)
		return false;
		
	else
		return true;
}

/**
* Purpose: Display a specific image on the the mouse down event.
*/
function onMouseDownEvent(elementId, onMouseClickImage)
{
	var imageElement = document.getElementById(elementId);
	
	if(imageElement) {
		imageElement.src = onMouseClickImage;
	}
}

$(window).load(function() {
	$('img').bind('dragstart', function(event) { event.preventDefault(); });
	$('img').draggable = false;
	$('img').onmousedown = function(event) {
                event.preventDefault();
                return false;
              };
});
document.ondragstart = function () { return false; };
