jQuery(document).ready( function($) {
 $slideshow = {
 context: true,
 tabs: false,
 timeout: 6000, // time before next slide appears (in ms)
 slideSpeed: 2000, // time it takes to slide in each slide (in ms)
 tabSpeed: 300, // time it takes to slide in each slide (in ms) when clicking through tabs
 fx: 'fade', // the slide effect options: http://malsup.com/jquery/cycle/browser.html http://malsup.com/jquery/cycle/

 init: function($, context, navContext) {
 // set the context to help speed up selectors/improve performance
 this.context = $(context);

 // set tabs to current hard coded navigation items
 this.tabs = $(navContext).find('li');

 // remove hard coded navigation items from DOM because they aren't hooked up to jQuery cycle
 this.tabs.remove();

 // prepare slideshow and jQuery cycle tabs
 this.prepareSlideshow($);
 },

 prepareSlideshow: function($) {
 // initialise the jquery cycle plugin - options: http://malsup.com/jquery/cycle/options.html
 $("div.carousel_images > ul", $slideshow.context).cycle({
 fx: $slideshow.fx,
 timeout: $slideshow.timeout,
 speed: $slideshow.slideSpeed,
 fastOnEvent: $slideshow.tabSpeed,
 pager: $("ul.carousel_nav", $(navContext)),
 pagerAnchorBuilder: $slideshow.prepareTabs,
 before: $slideshow.activateTab,
 pauseOnPagerHover: false,
 pause: false,
 next: jQuery(".carousel_images .next"),
 prev: jQuery(".carousel_images .previous")
 });
 },

 prepareTabs: function(i, slide) {
 // return markup from hardcoded tabs for use as jQuery cycle tabs
 return $slideshow.tabs.eq(i); // (attaches necessary jQuery cycle events to tabs)
 },

 activateTab: function(currentSlide, nextSlide) {
 var activeTab = jQuery('a[href="#' + nextSlide.id + '"]', $(navContext)); // get the active tab

 // if there is an active tab
 if(activeTab.length) {
 $slideshow.tabs.removeClass('on'); // remove active styling from all other tabs
 activeTab.parent().addClass('on'); // add active styling to active button
 }
 }
};

 // set the context to help speed up selectors/improve performance
 var sliderContext = $('.header_carousel');
 var navContext = $('#home_boxes');

 if ((sliderContext.length != 0) && (navContext.length != 0)) {
 // add a 'js' class to the slider for progressive enhancement
 $(sliderContext).parent().addClass('js');
 $(navContext).addClass('js');
 // start slideshow
 $slideshow.init($, $(sliderContext), $(navContext));
 }

 // stop slideshow - in case needed
 /*if ((sliderContext.length != 0) && ($("div.carousel_images > ul").length != 0)) {
 $("div.carousel_images > ul", $(sliderContext)).cycle('stop');
 }*/

});

jQuery.fn.supersleight = function(settings) {
 settings = jQuery.extend({
 imgs: true,
 backgrounds: true,
 shim: '/frontend/default/mylatheme/images/transparent.gif',
 apply_positioning: true
 }, settings);

 return this.each(function(){
 if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
 jQuery(this).find('*').andSelf().each(function(i,obj) {
 var self = jQuery(obj);
 // background pngs
 if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
 var bg = self.css('background-image');
 var src = bg.substring(5,bg.length-2);
 var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
 var styles = {
 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
 'background-image': 'url('+settings.shim+')'
 };
 self.css(styles);
 };
 // image elements
 if (settings.imgs && self.is('img[src$=png]')){
 var styles = {
 'width': self.width() + 'px',
 'height': self.height() + 'px',
 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
 };
 self.css(styles).attr('src', settings.shim);
 };
 // apply position to 'active' elements
 if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
 self.css('position', 'relative');
 };
 });
 };
 });
};

jQuery(document).ready( function($) {
 $('.homeBox a').supersleight({shim: '/frontend/default/mylatheme/images/transparent.gif'});
 $('#homeBox3').supersleight({shim: '/frontend/default/mylatheme/images/transparent.gif'});
 $('.pngfix').supersleight({shim: '/frontend/default/mylatheme/images/transparent.gif'});
 //$('body').supersleight({shim: '/frontend/default/mylatheme/images/transparent.gif'}); //use this to apply automatically
});


