// 
//  script.js
//  trunk
//  
//  Created by Callum Wilson on 2011-05-11.
//  Copyright 2011 Oxygen Kiosk. All rights reserved.
// 
//  Accordion recreated by Timo Rautiainen 2011-06-21
$(document).ready(function() {
    $('.inactive .subnav').slideUp();
        $.each($('ul.accordian > li > a'), function() {
            $(this).click(function(evt) {
                if(!$(this).parent().hasClass('active')) {
                    evt.preventDefault();
                    $('ul.accordian').find('.active').removeClass('active').addClass('inactive').children('ul').slideUp();
                    $(this).parent().removeClass('inactive').addClass('active');
                    $(this).next('ul').delay(500).slideDown();
                } else {
                    return false;
                }
            });
    });
	$('#tabs a').click(function(e) {
		e.preventDefault();
		$('#tabs').find('.active').removeClass('active');
		$(this).parent().addClass('active');
		var id = $(this).attr('href');
		if ($('body').attr('id') == 'downloads' || $('body').attr('id') == 'links') {
			$('.downloads .active').removeClass('active');
			$(id).addClass('active');
		} else {
			$('#product-wrapper .active').removeClass('active');
			$(id).addClass('active');	
		}
	})
	
   /* $('#product-wrapper > div:first-child').addClass('active');
    $('#product-wrapper').css("height", $('#product-wrapper div.active').height());
    $('.tab-button').click(function(){
    $('.tab').removeClass("active").addClass("inactive");
    $(this).parent().addClass("active").removeClass("inactive");
    $('#product-wrapper').css("height", $(this).parent().height());});
	*/
	$('.gallery a').click(function(){
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");
		var largeRel = $(this).attr("rel");
		$(".image-product img").attr({ src: largePath, alt: largeAlt });
		$("span.title").html(largeAlt);
		$("span.code").html(largeRel);
		return false;
	});
		$('body').removeClass('nojs');
		$('#other-products > li > a').click(function(){
			$(this).parent.siblings().removeClass('open');
			$(this).parent.addClass('open');
			return false;
		});
		$('a').each(function() {
		   var a = new RegExp('/' + window.location.host + '/');
		   if(!a.test(this.href)) {
		       $(this).click(function(event) {
		           event.preventDefault();
		           event.stopPropagation();
		           window.open(this.href, '_blank');
		       });
		   }
		});
		$('#store #main a').attr("target","_blank");
});
