/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

jQuery(document).ready(function() {

    // Frameblocker
    if (top.location != self.location) {
        top.location = self.location;
    }
    
    // Produkt-Pflichtangaben
    jQuery('ul.options-list input:radio + span').each(function(intIndex) {
        jQuery(this).addClass('options_bg_' + (intIndex+2));
    });
    
    // Gallery
    if (document.getElementById('box-gallery')) {
    
		jQuery('.gallery_list_unstyled').addClass('gallery_list'); // adds new class name to maintain degradability
		
		jQuery('ul.gallery_list').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
	}
});

// Language-Change
function changeLanguage() {
    if (navigator.appName == 'Netscape') {
        var language = navigator.language;
    }
    else {
        var language = navigator.browserLanguage;
    }
    if (language.indexOf('en') > -1) self.location.href='/shop/english/home';
    else if (language.indexOf('es') > -1) self.location.href='/shop/spanish/home';
    else if (language.indexOf('fr') > -1) self.location.href='/shop/french/home';
    else if (language.indexOf('pl') > -1) self.location.href='/shop/polnish/home';
    else if (language.indexOf('ru') > -1) self.location.href='/shop/russian/home';
    else self.location.href='/shop/default/home';
}
