var is_opera =  navigator.userAgent.indexOf('Opera') > -1;
var is_safari = navigator.userAgent.indexOf('AppleWebKit/') > -1;
var is_chrome = navigator.userAgent.indexOf('Chrome') > -1;
var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
var is_mac = navigator.platform.toLowerCase().indexOf('mac') > -1;
var is_linux = navigator.platform.toLowerCase().indexOf('linux') > -1;
var ie6 = false;
var ie7 = false;
var ie8 = false;


$(document).ready(function() {

        
	if(typeof slideshow_handler == 'object') {
		slideshow_handler.setup();
	}
		
	$('#product-gallery a').colorbox();

    var all_links = $('a');
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();

    all_links.map(function(i, el){
        if($(el).attr('href').indexOf('http://') != -1 && $(el).attr('href').indexOf(hostname) == -1) {
            $(el).attr('target', '_blank');
        }
    })
	
	if(ie6) {
		ie_png_classes.setup();
	}
	
	if(is_safari) {
		$('body').addClass('browser-safari');
	}

	if(is_opera) {
		$('body').addClass('browser-opera');
	}

	$('#article-container tr').map(function(i, el){
		if(i%2==0) {
			$(el).addClass('odd');
		} else {
			$(el).addClass('even');
		}
    })
	
});



var ie_png_classes =  {
	setup: function() {
		return;
		/*
		$('#call-us').map(function(i, el){
			//var related_a = $('a', el)[0];
			var related_image = $('img', el)[0];
			$(el).addClass('has_png');
            el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='" + $(related_image).attr('src') + "', sizingMethod='crop')";
		});*/
	}
}




var slideshow_handler = {
    container: null,
	items: [],
    total_items: null,
    last_item: null,
    delay: 4000,
	animation: true,
    
    setup: function()  {
		this.container = $('#featured-product');
		if(!this.container) return;
		
		this.items = $('.product', this.container);
		this.total_items = this.items.length;
		if(this.items <= 2 ) return;
		
		setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay);
		this.last_item = 0;
		
		/*$('#featured-product').bind('mouseover', function(event) {
			slideshow_handler.animation = false;
        });*/

    },
    
    changePic: function() {
		var last_pic = $('#featured-product .active');
		var next_index = this.last_item + 1;
		if(next_index == this.total_items) {
			next_index = 0;
		}
		
		$(last_pic).animate({
			opacity: 0
		  }, 1000, function() {
			$(last_pic).removeClass('active')
		});
		setTimeout(function(){}, slideshow_handler.delay + 1000);
	
		var next_pic = $('#featured-product .product')[next_index];
		$(next_pic).css({'opacity':'0'});
		$(next_pic).addClass('active');
		$(next_pic).animate({
			opacity: 1
		  }, 1000, function() {
			// Animation complete.
		});
		
		this.last_item = next_index;
		if(slideshow_handler.animation) {
			setTimeout(function(){ slideshow_handler.changePic(); }, slideshow_handler.delay + 1000);	
		}
		
    }
}
