function log(a){
try{
  console.log(a);
  }catch(er){
   try{
     window.opera.postError(a);
     }catch(er){
     //no console avaliable. put 
     //alert(a) here or write to a document node or just ignore
     }
  }
}

var timeOuts = [];
var dipHome = 0;
var activeSecondary = '';
var myHeight = 0;
var totalHeight = 0;
var resizeTimer;

String.prototype.parseURL = function () {
    return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function (url) {
        return url.link(url);
    });
};

String.prototype.parseDate = function () {
    var v = this.split(' '); var dte = new Date(Date.parse(v[1] + " " + v[2] + ", " + v[5] + " " + v[3] + " UTC"));
    return (dte.getMonth() + 1) + '/' + dte.getDate() + '/' + dte.getFullYear();
}

var resizeText = function (size) {   
  	var myCookie = jQuery.cookie('fontSize', size); 
  	redrawFonts(size);
} 

var redrawFonts = function(size) {
	$body = jQuery("body").removeClass('resize0');
	$body.removeClass('resize1');
	$body.removeClass('resize2');
	$body.addClass('resize' + String(size));
}

var tw = function (data) {
	jQuery(".sideBarTwitterFeed").append('<img src="http://c3212742.r42.cf0.rackcdn.com/twitterTop.png" /><div id="tweets" />');
	//jQuery(".sideBarTwitterFeed").append('<img src="http://marathon.brandextract.com/images/obfT.jpg" /><div id="tweets" />');
	jQuery.each(data, function (i, item) {
		jQuery("<div/>").html('<div class="tweet"><p>' + String(item.text).parseURL() + '<br/>' + String(item.created_at).parseDate() + ' | <a href="http://twitter.com/intent/tweet?in_reply_to='+item.id_str+'">reply</a> | <a href="http://twitter.com/intent/retweet?tweet_id='+item.id_str+'">retweet</a> | <a href="http://twitter.com/intent/favorite?tweet_id='+item.id_str+'">favorite</p></div>').appendTo("#tweets");
	});
}

var emailPage = function() {
	temploc='http://www.marathonoil.com/About_Us/Contacts/Email_Page/?myURL=';
	temploc = temploc + window.location.href.replace(/\&/, '%26').replace(/\?/, '%3F');
	window.location.href = temploc;
}

var printPage = function() {
	window.print();
}

var showAccordionByID = function(thisAccordionID) {
	jQuery('#accordionTab'+thisAccordionID).addClass('active');
	jQuery('#accordionContent'+thisAccordionID).slideDown(200);
}

var hideAccordionByID = function(thisAccordionID) {
	jQuery('#accordionTab'+thisAccordionID).removeClass('active');
	jQuery('#accordionContent'+thisAccordionID).slideUp(200);
}

var accordionsOpen = function() {
	result = 0;
	jQuery("#inlineAccordion > div.inlineAccordionTab").each(function (i) {
		temp = jQuery(this).css("background-image");
		if (temp.indexOf('up') != -1) {
			result++;
		}
	});
	return result;
}

var fitList = function(id, height) {
	$this = jQuery(id);
	$ul = $this.find('ul');
	$ul.height() < height ? toBig = false : toBig = true;
	if (toBig) {
		do {
			$ul.find('li:last').remove();
			if ($ul.height() < height) toBig = false;
		} while (toBig);
	}
}

var updateCollapser = function() {
	if (jQuery("#inlineAccordion > div.inlineAccordionTab").length/2 >= accordionsOpen()) {
		jQuery("#expand").attr('src', '/images/spacer.gif');
	} else {
		jQuery("#expand").attr('src', '/images/spacer.gif');
	}
	if (accordionsOpen() == 1 || accordionsOpen() == 0) {
		jQuery("#accSpacer").height(myHeight);
	} else {
		jQuery("#accSpacer").height(totalHeight);
	}
}

var apikey='26d7b275ba37b30e29b36623f18fac85',userid='35458411@N04';

function getSets(){
	jQuery.getJSON('http://api.flickr.com/services/rest/?jsoncallback=?',{method:'flickr.photosets.getList',api_key:apikey,user_id:userid,format:'json'},function(obJ){
		var photoSets = obJ.photosets.photoset;
		jQuery('.galleryShowMore>.target').live('click', function() { 
			jQuery(this).hide().next().show();	
		});
		jQuery('.galleryThumb').live('click', function() {
			
		});
		jQuery(".flickerGallery").each( function() {
			var thisGallery, galleryName;
			$this = jQuery(this);
			galleryName = $this.attr('rel');
			for(i=0, j=photoSets.length;i<j;i++) {
				if(photoSets[i].title._content == galleryName) thisGallery = photoSets[i];
			}
			if (typeof(thisGallery) != "undefined") {
				$this.append('<h2>'+galleryName+'</h2><div class="galleryThumbs" rel="'+thisGallery.id+'"><img src="/images/loading.gif" /></div><div class="clear" />');
				jQuery.getJSON('http://api.flickr.com/services/rest/?jsoncallback=?',{method:'flickr.photosets.getPhotos',api_key:apikey,photoset_id:thisGallery.id,format:'json'},function(obj){
					$galleryDiv = jQuery('div[rel='+thisGallery.id+']');
					$galleryDiv.empty();
					var photoset = obj.photoset;
					for(i=0, mylength = photoset.photo.length;i<6 && i<mylength;i++) {
						thisImg = photoset.photo[i];
						$galleryDiv.append('<div class="galleryThumb"><a title="'+thisImg.title+'" href="http://farm'+thisImg.farm+'.static.flickr.com/'+thisImg.server+'/'+thisImg.id+'_'+thisImg.secret+'.jpg'+'" class="thickbox"><img alt="'+thisImg.title+'" src="'+'http://farm'+thisImg.farm+'.static.flickr.com/'+thisImg.server+'/'+thisImg.id+'_'+thisImg.secret+'_s.jpg'+'" class="galleryThumb" /></a></div>');
					}
					if (photoset.photo.length > 6) {
						$galleryDiv.append('<div class="galleryShowMore clear"><div class="target">Show All</div><div class="moreImages"></div></div>');
						for(i=6, mylength = photoset.photo.length;i<mylength;i++) {
						thisImg = photoset.photo[i];
						$galleryDiv.find('.moreImages').append('<div class="galleryThumb"><a title="'+thisImg.title+'" href="'+'http://farm'+thisImg.farm+'.static.flickr.com/'+thisImg.server+'/'+thisImg.id+'_'+thisImg.secret+'.jpg'+'" class="thickbox"><img src="'+'http://farm'+thisImg.farm+'.static.flickr.com/'+thisImg.server+'/'+thisImg.id+'_'+thisImg.secret+'_s.jpg'+'" class="galleryThumb" /></a></div>');
					}
					}
				});
			}
		});
	});
}

/* YouTube Data Call Back */
var yt = function (data) {
	var myLength = data.feed.entry.length;
	jQuery(".embedYouTubeVideo").each( function () {
		var $this = jQuery(this);
		var keyword = $this.attr('rel');
		for (i=0;i<myLength;i++) {
			var item = data.feed.entry[i];
			var myKeywords = item.media$group.media$keywords.$t;
			if(myKeywords.indexOf(keyword) > -1) {
				MYID = 'vid'+keyword+'Vid'+String(i);
				if ($this.hasClass('multi')) {
					$this.append('<div class="youtubeVideoMulti"><div id="'+MYID+'"></div><div class="youTubeVideoDescription"><h2>'+item.title.$t+'</h2><p>'+item.media$group.media$description.$t+'</p><div class="clear"></div></div>');
					swfobject.embedSWF(item.content.src+'&rel=0', MYID, "120", "90", "9.0.0","expressInstall.swf", {}, {wmode:"transparent"}, {});
				} else {
					if ($this.hasClass('homeVideo')) {
						$this.append('<div class="youtubeVideoHome" id="'+MYID+'"></div>');
						i=myLength;
						swfobject.embedSWF(item.content.src+'&rel=0', MYID, "302", "224", "9.0.0","expressInstall.swf", {}, {wmode:"transparent"}, {});
					} else {
						$this.append('<div class="youtubeVideo" id="'+MYID+'"></div><div class="youTubeVideoDescription"><h2>'+item.title.$t+'</h2><p>'+item.media$group.media$description.$t+'</p><div class="clear"></div>');
						i=myLength;
						swfobject.embedSWF(item.content.src+'&rel=0', MYID, "360", "270", "9.0.0","expressInstall.swf", {}, {wmode:"transparent"}, {});
					}
				}
				
			}
			
		}
	});
	/*var $vidPage = jQuery("#videoPage");
	if ($vidPage.length > 0) {
		for(i=0;i<myLength;i++) {
			var item = data.feed.entry[i];
			var myKeywords = item.media$group.media$keywords.$t;
			
		}
	}*/
}

var homeImageClasses = ['homeImage1','homeImage2','homeImage3','homeImage4','homeImage5'], homeImage = 0;

var rotateHomeImage = function() {
	homeImage+1 == homeImageClasses.length ? homeImage = 0 : homeImage++;
	$this = jQuery('.rotatingHomeImage');
	$this.wrap('<div class="rotatingHomeImage '+homeImageClasses[homeImage]+'"></div>');
	$this.fadeOut(1000, function() {jQuery(this).remove();});
	setTimeout("rotateHomeImage()",5000);
}


jQuery(function () {
    jQuery.noConflict();
    setTimeout("jQuery('#inline').css('min-height', jQuery('#leftNav').height()+40)", 100);
    try {
    	jQuery("#stockTicker").load('https://www.marathonoil.com/content/includes/AJAXtwister.asp?type=2011homequote');
    }
    catch(ex) {
    	var script   = document.createElement("script");
		script.type  = "text/javascript";
		script.src   = "https://www.marathonoil.com/content/includes/AJAXtwister.asp?type=homequoteinjection";
		document.body.appendChild(script);
    }
    	
    

    if (jQuery.cookie('fontSize') === null) {
        resizeText(1);
    } else {
        redrawFonts(jQuery.cookie('fontSize'));
    }

    initializePage = function (id, primaryid) {

        /* World Map Code */
        if (jQuery("#countryList").length > 0) {
            /* Drop Down */
            jQuery("#countryList").bind('change', function () {
                if (jQuery(this).find("option:selected").val() != '') {
                    window.location.href = jQuery(this).find("option:selected").val();
                }
            });
        }
        if (id == 1908) {
            /* Map Hotspots */
            jQuery(".wmHotSpot").each(function () {
                var $this = jQuery(this);
                $this.find('img').css('height', $this.height()).css('width', $this.width());
            }).click(function () {
                jQuery('.wmHotSpot').show();
                var $this = jQuery(this).hide();
                jQuery('.popup').hide();
                jQuery('#pu' + $this.attr('id')).fadeIn(250);
            });

            /* Popup Close Buttons */
            jQuery(".popupCloser").click(function () {
                var $this = jQuery(this);
                jQuery("#" + $this.find('img').attr('rel')).fadeIn(125);
                $this.parents('.popup').hide();
            });
        }

        /* Image Gallery specific code */
        if (id == 2043) {
			getSets();
		}
		
		/* Home Page Specific Code */
        if (id == 1907) {
            jQuery("#tabContentPR").load('/content/includes/AJAXtwister.asp?type=2011NewsReleasesHome', function () {
                fitList("#tabContentPR", 380);
            });
            jQuery("#tabContentEvents").load('/content/includes/AJAXtwister.asp?type=2011EventsHome');
            jQuery("#tabEvents").live("click", function() {
            	setTimeout("fitList('#tabContentEvents', 380)", 10);
            });
            /* Set timer */
            setTimeout("rotateHomeImage()", 5000);

        }

        /* News Page Specific Code */
        if (id == 1910) {
            jQuery("#tabContent3828").load('/content/includes/AJAXtwister.asp?type=2011NewsReleasesHome', function () {
                fitList("#tabContent3828", 345);
            });
        }

        /* Press Releases Specific Code */
        if (id == 2039) {
            jQuery(function () { jQuery('#pressReleases').load('/content/includes/AJAXtwister.asp?type=2011NewsReleases'); });
        }

        /* Investor Center Home Code */
        if (primaryid == 1909) {
            try {
				jQuery("#newsEventsSidebar").load('http://www.marathonoil.com/content/includes/AJAXtwister.asp?type=2011IRSidebarNews', function () {
					fitList("#newsEventsSidebar", 300 );
					jQuery("#eventsContent").load('http://www.marathonoil.com/content/includes/AJAXtwister.asp?type=2011IRSidebarEvents', function() {
						if (id == 1909) {	
							jQuery("#eventsTab").swapWith("#pressReleasesTab").hide();
						}
						jQuery("#eventsTab").live( "click", function() {
							setTimeout("fitList('#eventsContent', 300 )", 10);
						});
						if (id == 1909) {	
							jQuery("#eventsTab").trigger("click");
						}
					});
				});
				
			}
			catch(ex) {
				var script   = document.createElement("script");
				script.type  = "text/javascript";
				script.src   = "http://www.marathonoil.com/content/includes/AJAXtwister.asp?type=2011IRSidebarNewsinjection";
				document.body.appendChild(script);
			}
        }

        /* Spotlight Series Specific Code */
        if (id == 2045) {
            jQuery("#featureArea").load('/content/includes/AJAXtwister.asp?type=spotlightImageRotator2011');
        }
		
		/* We Work with Care Specific Code */
        if (id == 2118) {
            jQuery("#featureArea").load('/content/includes/AJAXtwister.asp?type=weWorkWithCare2011');
        }

        /* Shade Button Code */
        /* Shade Button Configurator */
        jQuery(".shadebutton").each(function () {
            var $this = jQuery(this), myTarget = $this.parent().attr('href'), myLabel = $this.parent().attr('title'), myDescription = $this.attr('alt'), myWidth = $this.width(), myHeight = $this.height();
            $this.parent().wrap('<div class="shadebuttonwrapper" />').before('<div class="shadebuttonlabel">' + myLabel + '</div>', '<div class="shadeclipper"><div class="shadebuttontab sprite"><div class="shadebuttondesc">' + myDescription + '</div></div></div>', '<a href="' + myTarget + '" class="shadebuttontrigger" title=""><img src="http://www.marathon.com/images/spacer.gif" alt="" /></a>');
            $this.parent().siblings('.shadeclipper, .shadebuttontrigger').css('width', String(myWidth + 'px')).css('height', String(myHeight + 'px')).find('.shadebuttontab').css('width', String(myWidth + 'px'));
            $this.parent().siblings('.shadebuttontrigger').find('img').css('width', String(myWidth + 'px')).css('height', String(myHeight + 'px'));
        });

        /* Shadebutton Watcher */
        jQuery('.shadebuttontrigger').hover(function () {
            var $this = jQuery(this);
            $this.siblings('.shadeclipper').find('.shadebuttontab').animate({ marginTop: 0 }, 125, "swing");
        }, function () {
            var $this = jQuery(this);
            $this.siblings('.shadeclipper').find('.shadebuttontab').animate({ marginTop: -99 }, 500, "swing");
        });
        
        /* Alternate (Bottom Up) Shade Button Configurator */
        jQuery(".BUshadebutton").each(function () {
            var $this = jQuery(this), myTarget = $this.parent().attr('href'), myLabel = $this.parent().attr('title'), myDescription = $this.attr('alt'), myWidth = $this.width(), myHeight = $this.height();
            $this.parent().wrap('<div class="BUshadebuttonwrapper" />').before('<div class="BUshadebuttonlabel">' + myLabel + '</div>', '<div class="BUshadeclipper"><div class="BUshadebuttoncorner"></div><div class="BUshadebuttontab"><div class="BUshadebuttondesc">' + myDescription + '</div></div></div>', '<a href="' + myTarget + '" class="BUshadebuttontrigger" title=""><img src="http://www.marathon.com/images/spacer.gif" alt="" /></a>');
            $this.parent().siblings('.BUshadeclipper, .BUshadebuttontrigger').css('width', String(myWidth + 'px')).css('height', String(myHeight + 10 + 'px')).find('.BUshadebuttontab').css('width', String(myWidth + 'px'));
            $this.parent().siblings('.BUshadebuttontrigger').find('img').css('width', String(myWidth + 'px')).css('height', String(myHeight + 'px'));
        });
        
        /* Alternate (Bottom Up) Shadebutton Watcher */
        jQuery('.BUshadebuttontrigger').hover(function () {
            var $this = jQuery(this);
            $this.siblings('.BUshadeclipper').find('.BUshadebuttontab').animate({ marginTop: -1 }, 125, "swing");
        }, function () {
            var $this = jQuery(this);
            $this.siblings('.BUshadeclipper').find('.BUshadebuttontab').animate({ marginTop: 98 }, 500, "swing");
        });

        /* WavyImage Code */
        jQuery(".wavyImage").each(function () {
            var $this = jQuery(this), myDescription = $this.attr('alt'), myWidth = $this.width(), myHeight = $this.height();
            $this.wrap('<div class="wavyImageWrapper" />').before('<div class="wavyImageWaves sprite" />');
            $this.siblings('.wavyImageWaves').css('width', String(myWidth + 'px')).css('height', String(myHeight + 'px'));
        });

        /* Search Box Watcher */
        jQuery("#q").focus(
			function () {
			    if (this.value == 'Search this site...') this.value = '';
			}
		).blur(
			function () {
			    if (this.value == '') this.value = 'Search this site...';
			}
		);
		
		/* Press Release Search Box Watcher */
        jQuery("#prq").live( 'focus',
			function () {
			    if (this.value == 'Search press releases...') this.value = '';
			}
		).live('blur',
			function () {
			    if (this.value == '') this.value = 'Search press releases...';
			}
		);

        /* Overlapping Tab Code */
        /* Code needs to be tweaked if we are going to have multiple tab groups on a page */
        jQuery(".oTab.target").live("click", function () {
            var $this = jQuery(this);
            var $that = jQuery("#" + $this.attr('rel'));
            $this.closest(".oTabGroup").find(".oTabContent").removeClass("active");
            $this.closest(".oTabGroup").find(".oTab").removeClass("active").removeClass("nextActive");
            $this.addClass("active").prev().addClass("nextActive").next().next().addClass("active");
            $that.addClass("active");
        });

        /* Inline Accordion Code */
        if (jQuery("#inlineAccordion").length > 0) {
            jQuery("#inlineAccordion > div.inlineAccordionContent").each(function (i) {
                // Find the ideal height to display the tallest single accordion
                if (jQuery(this).height() > myHeight) myHeight = jQuery(this).height();
                // Calculate the ideal height to display all accordions
                totalHeight += jQuery(this).height() + 44;
            });

            myHeight += 208;

            jQuery("#inlineAccordion > div.inlineAccordionTab").each(function (i) {
                // Add in the height of each tab
                myHeight += jQuery(this).height();
                totalHeight += jQuery(this).height();
            });

            jQuery(".inlineAccordionTab").bind("click", function (e) {
                $this = jQuery(this);
                if ($this.hasClass('active') == false) {
                    setTimeout('showAccordionByID(' + $this.attr('id').substring(12) + ')', 250)
                }
                if (accordionsOpen() > 1) {
                    hideAccordionByID($this.attr('id').substring(12));
                } else {
                    jQuery(".inlineAccordionContent").slideUp(200);
                    jQuery(".inlineAccordionTab").removeClass('active');
                }
                updateCollapser();
            });

            jQuery("#accSpacer").height(totalHeight);

            jQuery("#expand").bind("click", function (e) {
                if (jQuery("#inlineAccordion > div.inlineAccordionTab").length / 2 >= accordionsOpen()) {
                    jQuery("#inlineAccordion > div.inlineAccordionContent").each(function (i) { jQuery(this).slideDown(200); });
                    jQuery("#inlineAccordion > div.inlineAccordionTab").each(function (i) { jQuery(this).addClass('active') });
                } else {
                    jQuery("#inlineAccordion > div.inlineAccordionContent").each(function (i) { jQuery(this).slideUp(200); });
                    jQuery("#inlineAccordion > div.inlineAccordionTab").each(function (i) { jQuery(this).removeClass('active') });
                }
                updateCollapser();
            });
        }

        jQuery(".resizer").hover(function () { jQuery("#resizeTool").css("background-position", "0px -840px"); }, function () { jQuery("#resizeTool").css("background-position", "0px -860px"); });

        jQuery(".lovTable tr:odd").addClass("blue");

    }

    activateRollovers = function () {
        // This nonsense is here because some browsers try and run this bit before elements have their offset top and left defined
        if (
			jQuery("#primaryNav>div>ul>li:eq(0)").offset().left != jQuery("#primaryNav>div>ul>li:eq(1)").offset().left
		) {
            $activePrimary = jQuery("#primaryNav li.active");
            $activePrimary.length > 0 ? dipHome = $activePrimary.offset().left : dipHome = 0;
            jQuery("#ulNav1908").pacNav({ "type": "primary", "dd": "#globalDD" });
            jQuery("#ulNav1909").pacNav({ "type": "primary", "dd": "#investorDD" });
            jQuery("#ulNav1910").pacNav({ "type": "primary", "dd": "#newsDD" });
            jQuery("#ulNav1911").pacNav({ "type": "primary", "dd": "#socialDD" });
            jQuery("#ulNav1912").pacNav({ "type": "primary", "dd": "#careersDD" });
            jQuery("#ulNav1913").pacNav({ "type": "primary", "dd": "#aboutDD" });
            jQuery(".dropDownContainer").pacNav({ type: 'dropdown' });
        } else {
            setTimeout("activateRollovers()", 100);
        }
    };

    jQuery(window).resize(function () {
        clearTimeout(timeOuts['resize']);
        timeOuts['resize'] = setTimeout('positionDropdowns();', 250);

    });

    positionDropdowns = function () {
        jQuery("#ulNav1908").each(function () { positionDD(jQuery(this), "#globalDD") });
        jQuery("#ulNav1909").each(function () { positionDD(jQuery(this), "#investorDD") });
        jQuery("#ulNav1910").each(function () { positionDD(jQuery(this), "#newsDD") });
        jQuery("#ulNav1911").each(function () { positionDD(jQuery(this), "#socialDD") });
        jQuery("#ulNav1912").each(function () { positionDD(jQuery(this), "#careersDD") });
        jQuery("#ulNav1913").each(function () { positionDD(jQuery(this), "#aboutDD") });
    }

    secondaryOff = function () {
        jQuery("#primaryDip").stop().animate({ "width": dipHome }, 200, "swing");
        jQuery(".dropDownContainer").stop().fadeOut("Fast");
        //jQuery("#"+activeSecondary).fadeOut("fast");

    }

    secondaryOn = function (left, dd) {
        jQuery("#primaryDip").stop().animate({ "width": left }, 200, "swing");
        activeSecondary = dd;
        jQuery(dd).fadeIn("fast");
    }

    stopTimeOut = function () {
        for (key in timeOuts) {
            clearTimeout(timeOuts[key]);
        }
    }

    positionDD = function ($this, dd) {
        var ddLeft = $this.offset().left - 40;
        var ddWidth = jQuery(dd).width();
        var maxLeft = jQuery('.pageWidth:eq(0)').width() + jQuery('.pageWidth:eq(0)').offset().left - ddWidth;
        if (ddLeft > maxLeft) ddLeft = maxLeft;
        jQuery(dd).css({ 'top': jQuery("#primaryIndicator").offset().top + 1, 'left': ddLeft });
    }

    jQuery.fn.pacNav = function (params) {
        this.each(function () {
            var $this = jQuery(this);
            positionDD($this, params.dd);
            var dipLeft = $this.offset().left + 140;

            if (jQuery($this).hasClass("active")) {
                jQuery("#primaryDip").stop().css({ "width": dipLeft }).show();
                dipHome = dipLeft;
            }

            jQuery(this).bind("mouseover", function () {
                var $this = jQuery(this);
                switch (params.type) {
                    /*case 'primary':
                    jQuery(this).attr("src",params.on); 
                    break;*/ 
                    case 'dropdown':
                        stopTimeOut();
                        break;
                    default:
                        stopTimeOut();
                        left = $this.offset().left + 140;
                        timeOuts["mouseIn"] = setTimeout("secondaryOn(" + left + ", '" + params.dd + "')", 125);
                        if (activeSecondary != params.dd) {
                            jQuery(activeSecondary).fadeOut("fast");
                        }


                }
            });
            jQuery(this).bind("mouseout", function () {
                switch (params.type) {
                    /*case 'primary':
                    jQuery(this).attr("src",params.off); 
                    break;*/ 
                    default:
                        stopTimeOut();
                        timeOuts["mouseOut"] = setTimeout("secondaryOff()", 300);
                }
            });
        });
    };

    activateRollovers();

});

/*jslint browser: true */ /*global jQuery: true */

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 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
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key 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 key The key 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 key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key 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 (key, value, options) {
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

	
jQuery(document).ready(function(){
	jQuery(".thickboxcust").bind("click", function(e){
		e.preventDefault();
		var url = jQuery(this).attr("href");
		tb_show('',url+'?KeepThis=true&amp;TB_iframe=true&amp;height=580&amp;width=570');
	});
							
	jQuery(".thickboxAR").bind("click", function(e){
		e.preventDefault();
		var url = jQuery(this).attr("href");
		tb_show('',url+'?KeepThis=true&amp;TB_iframe=true&amp;height=470&amp;width=670');
	});
	

	
});

jQuery.fn.swapWith = function(to) {
    return this.each(function() {
        var copy_to = jQuery(to).clone(true);
        var copy_from = jQuery(this).clone(true);
        jQuery(to).replaceWith(copy_from);
        jQuery(this).replaceWith(copy_to);
    });
};


/*


	
	
	
	
	activateRollovers = function () {
		// This nonsense is here because sometimes browsers try and run this bit before elements have their offset top and left defined
		if (jQuery("#secondaryNav>ul>li:eq(0)").offset().left != jQuery("#secondaryNav>ul>li:eq(1)").offset().left) {
			jQuery("#primaryLab").pacNav({ off: '/images/lab_instruments.png', on: '/images/lab_instruments_over.png', type: 'primary' });
			jQuery("#primaryProcess").pacNav({ off: '/images/process_analytics.png', on: '/images/process_analytics_over.png', type: 'primary' });
			jQuery("#primaryParts").pacNav({ off: '/images/parts_store.png', on: '/images/parts_store_over.png', type: 'primary' });
			jQuery("#primarySupport").pacNav({ off: '/images/customer_support.png', on: '/images/customer_support_over.png', type: 'primary' });
			jQuery("#primaryNews").pacNav({ off: '/images/news_and_events.png', on: '/images/news_and_events_over.png', type: 'primary' });
			jQuery("#primaryAbout").pacNav({ off: '/images/about_pac.png', on: '/images/about_pac_over.png', type: 'primary' });
			jQuery("#secondaryNav>ul>li").pacNav({type: 'secondary' });
			jQuery(".dropDownContainer").pacNav({type: 'dropdown' });
			jQuery("#zoomableImage").each( function () {
				myLeft = jQuery(this).offset().left + (jQuery(this).width());
				myTop = jQuery(this).offset().top + (jQuery(this).height());
				jQuery("#lightboxArrow").offset({ top: myTop, left: myLeft });
			});
		} else {
			setTimeout("activateRollovers()", 100);
		}
	};
	
	activateRollovers();
	mytabs = jQuery("#tabbedContent > div.tabs").tabs("#tabbedContent > div.panes > div");
	jQuery("#footerSlideshow > div.tabs").tabs("#footerSlideshow > div.panes > div", { rotate: true}).slideshow({autoplay:true, autopause:true });
	jQuery(".dropDownParent").tabs(".dropDownChild > div", {initialIndex: 1000, event:'mouseover', onBeforeClick:function () { stopTimeOut() }});
	jQuery(".timeOutKiller").bind("mouseover", function () {
		stopTimeOut();
	});
	
	*/
