

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-07-21 18:45:56 -0500 (Sat, 21 Jul 2007) $
 * $Rev: 2447 $
 *
 * Version 2.1.1
 */
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);


/**
 * jQuery (PNG Fix) v1.2
 * Microsoft Internet Explorer 24bit PNG Fix
 *
 * The MIT License
 * 
 * Copyright (c) 2007 Paul Campbell (pauljamescampbell.co.uk)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @param		Object
 * @return		Array
 */
(function($) {
	
	$.fn.pngfix = function(options) {
		
		// Review the Microsoft IE developer library for AlphaImageLoader reference 
		// http://msdn2.microsoft.com/en-us/library/ms532969(VS.85).aspx
		
		// ECMA scope fix
		var elements 	= this;
		var settings 	= $.extend({
			imageFixSrc: 	false,
			sizingMethod: 	false 
		}, options);
		
		if(!$.browser.msie || ($.browser.msie &&  $.browser.version >= 7)) {
			return(elements);
		}

		function setFilter(el, path, mode) {
			var fs = el.attr("filters");
			var alpha = "DXImageTransform.Microsoft.AlphaImageLoader";
			if (fs[alpha]) {
				fs[alpha].enabled = true;
				fs[alpha].src = path; 
				fs[alpha].sizingMethod = mode;
			} else {
				el.css("filter", 'progid:' + alpha + '(enabled="true", sizingMethod="' + mode + '", src="' + path + '")');			
			}
		}
		
		function setDOMElementWidth(el) {
			if(el.css("width") == "auto" & el.css("height") == "auto") {
				el.css("width", el.attr("offsetWidth") + "px");
			}
		}

		return(
			elements.each(function() {
				
				// Scope
				var el = $(this);
				
				if(el.attr("tagName").toUpperCase() == "IMG" && (/\.png/i).test(el.attr("src"))) {
					if(!settings.imageFixSrc) {
						
						// Wrap the <img> in a <span> then apply style/filters, 
						// removing the <img> tag from the final render 
						el.wrap("<span></span>");
						var par = el.parent();
						par.css({
							height: 	el.height(),
							width: 		el.width(),
							display: 	"inline-block"
						});
						setFilter(par, el.attr("src"), "scale");
						el.remove();
					} else if((/\.gif/i).test(settings.imageFixSrc)) {
						
						// Replace the current image with a transparent GIF
						// and apply the filter to the background of the 
						// <img> tag (not the preferred route)
						setDOMElementWidth(el);
						setFilter(el, el.attr("src"), "image");
						el.attr("src", settings.imageFixSrc);
					}
					
				} else {
					var bg = new String(el.css("backgroundImage"));
					var matches = bg.match(/^url\("(.*)"\)$/);
					if(matches && matches.length) {
						
						// Elements with a PNG as a backgroundImage have the
						// filter applied with a sizing method relevant to the 
						// background repeat type
						setDOMElementWidth(el);
						el.css("backgroundImage", "none");
						
						// Restrict scaling methods to valid MSDN defintions (or one custom)
						var sc = "crop";
						if(settings.sizingMethod) {
							sc = settings.sizingMethod;
						} 
						setFilter(el, matches[1], sc);
						
						// Fix IE peek-a-boo bug for internal links
						// within that DOM element
						el.find("a").each(function() {
							$(this).css("position", "relative");
						});

					}
				}
				
			})
		);
	}

})(jQuery)

// BrowserDetect
var BrowserDetect={init:function(){this.browser=this.searchString(this.dataBrowser)||"An unknown browser";this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";this.OS=this.searchString(this.dataOS)||"an unknown OS"},searchString:function(data){for(var i=0;i<data.length;i++){var dataString=data[i].string;var dataProp=data[i].prop;this.versionSearchString=data[i].versionSearch||data[i].identity;if(dataString){if(dataString.indexOf(data[i].subString)!=-1)return data[i].identity}else if(dataProp)return data[i].identity}},searchVersion:function(dataString){var index=dataString.indexOf(this.versionSearchString);if(index==-1)return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};BrowserDetect.init();
// BrowserDetect

// Jquery

$(document).ready(function() {

	//BEGIN: .clear_value
	//Clear Header Search field's default text when you focus on it. Default value should be placed as the Input's Title attr.
	$(".clear_value").focus(function() {
		if ($(this).val() == $(this).attr("title")) {
			$(this).val("");
			$(this).removeClass("clear_value_off");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("title"));
			$(this).addClass("clear_value_off");
		}
	});
	
	
	//primary nav hover turns on dropdown
		$(".primary_nav tr:first > td:last").addClass("last");
		$(".primary_nav div").hover(
			function(){
				$(this).addClass("over");
				if($(this).hasClass("has_children")){
					$(this).addClass("has_children_over");
					if($(this).hasClass("dropdown_lvl_two")){
						var link_height = $(this, "a:first").height();
						link_height = ((link_height+1)*-1);
						$(".dropdown_subnav:first", this).css({"margin-top":link_height});
					}
				}
			},
			function(){
				$(this).removeClass("over").removeClass("has_children_over");
			}
		);
		//Place in for IE6 after more testing
		//$('.dropdown_nav').bgiframe();
	
	//header_pngfix
		//Place in for IE6 after more testing
		//$(".header_section_info").pngfix();
	
	//tabs
		//$("#tabs").tabs();
		$(".tabs").each(function(){$(this).tabs();});
	//form highlights
		$(".formcell").click( function() {
			$(".form_selected").removeClass("form_selected");
			$(this).addClass("form_selected");
		});
		// When user tab's through fields
		$(".formcell *").blur(function(){
			$(".form_selected").removeClass("form_selected");
		});
		$(".formcell *").focus(function(){
			$(this).parents(".formcell:first").addClass("form_selected");
		});
	
	// Font Size
		//reset fonts
		function resizeFonts(className,resizeOption){
			var currentFontSize = $(className).css('font-size');
			currentFontSizeNum = parseFloat(currentFontSize, 10);
			if(resizeOption=='equal'){
				$(className).css('font-size', '1em');
			}
			if(resizeOption=='plus'){
				if(currentFontSizeNum<=28){
					$(className).css('font-size', (currentFontSizeNum+2));
				}
			}
			if(resizeOption=='minus'){
				if(currentFontSizeNum>=10){
					$(className).css('font-size', (currentFontSizeNum-2));
				}
			}
			changeLineHeight(className);
			
			//FontCookie
			currentFontSize = $(className).css('font-size');
			currentFontSizeNum = parseFloat(currentFontSize, 10);
			$.cookie('fontCookieClass', className);
			$.cookie('fontCookieNum', currentFontSizeNum);
		}
		
		//Line height fix for change of value
		function changeLineHeight(className){
			var currentFontSize = $(className).css('font-size');
			currentFontSizeNum = parseFloat(currentFontSize, 10);
			if (currentFontSizeNum>=1){$(className).css('line-height', '9px');}
			if (currentFontSizeNum>=9){$(className).css('line-height', '18px');}
			if (currentFontSizeNum>=18){$(className).css('line-height', '36px');}
			if (currentFontSizeNum>=36){$(className).css('line-height', '54px');}
			if (currentFontSizeNum>=54){$(className).css('line-height', '72px');}
		}
		//click actions
		$(".resetFont").click( function(){resizeFonts($(this).attr('rel'),'equal'); return false;} );
		$(".increaseFont").click(function(){resizeFonts($(this).attr('rel'),'plus'); return false;} );
		$(".decreaseFont").click(function(){resizeFonts($(this).attr('rel'),'minus'); return false;} );

		if ($.cookie('fontCookieNum')){
			currentFontSizeNum = $.cookie('fontCookieNum');
			if ($.cookie('fontCookieClass')){
				className = $.cookie('fontCookieClass');
			}
			$(className).css('font-size', currentFontSizeNum++);
			changeLineHeight(className);
		}
	//sales_cat_item
		if(".cat_listing"){
			$("#cat_listing a").click(function(){
				var cat_link_href = $(this).attr("href");
				$(".sales_category").hide();
				$("#cat_listing li").removeClass("on");
				$(this).parents("li:first").addClass("on");
				if($(cat_link_href).is("div")){
					$(cat_link_href).show();
				} else {
					$(".sales_category").show();
				}
				$("#cat_name").text($(this).text());
				return false;
			});
		}
		
	// Manuals - show and hide
	    $(".manual_info").hide();
		$(".manual_name").click( function() {
			$(this).parents("TR:first").find(".manual_info").toggle();
		});
		
	//FAQ
		if ($(".faq").length){
			$(".faq_a").hide();
			$(".faq_content a").click(function(){ $(this).parents(".faq_item:first").find(".faq_a:first").slideToggle(); return false;});
		}
		
	// IE7 Partner Portal Display issue with .section_nav_seperation Bulletins title; #0023180 
	var browser = BrowserDetect.browser;
	var version = BrowserDetect.version;
	if(browser == "Explorer") {
		if(version == 7) {
			$(".section_nav_seperation:first").after( $(".section_nav_seperation:first").html() ).html("");
		}
	};
	
});

// BEGIN:year functions
     function currentyear()
        {
             var now= new Date();
             var intyear= now.getFullYear();
             document.write(intyear);
        }

    // END: year functions
