/*
 * jQuery ifixpng plugin
 * (previously known as pngfix)
 * Version 2.1  (23/04/2008)
 * @requires jQuery v1.1.3 or above
 *
 * Examples at: http://jquery.khurshid.com
 * Copyright (c) 2007 Kush M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
  
(function($) {

	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || 'images/pixel.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && $.browser.version < 7,
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);

			// in case rewriting urls
			var base = $('base').attr('href');
			if (base) {
				// remove anything after the last '/'
				base = base.replace(/\/[^\/]+$/,'/');
			}
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src')) {
					if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
						// use source tag value if set 
						var source = (base && $$.attr('src').search(/^(\/|http:)/i)) ? base + $$.attr('src') : $$.attr('src');
						// apply filter
						$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
						  .attr({src:$.ifixpng.getPixel()})
						  .positionFix();
					}
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					image = (base && image.substring(0,1)!='/') ? base + image : image;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .children().children().positionFix();
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[@src$=.png]').iunfixpng();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').iunfixpng();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name iunfixpng
	 */
	 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);



/* Infinite Carousell 
*  Made By JQueryForDesigners.com
*/

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {

		       
		var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),

			singleWidth = $single.outerWidth(),
			visible = Math.ceil($wrapper.innerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.ceil($items.length / visible); 
			

 
        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<span class="prevBtn"><a href="javascript:void(0);" class="png">Previous</a></span>');
		$wrapper.after('<span class="nextBtn"><a href="javascript:void(0);" class="png">Next</a></span>');
        
        // 5. Bind to the forward and back buttons
        $('.prevBtn', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('.nextBtn', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};



/*
* "jQuery checkbox v.1.3.0 Beta 1"
* http://widowmaker.kiev.ua/checkbox/
*/

displayForm = function (elementId)	{
				var content = [];
				$('#' + elementId + ' input').each(function(){
					var el = $(this);
					if ( (el.attr('type').toLowerCase() == 'radio'))
					{
						if ( this.checked )
							content.push([
								'"', el.attr('name'), '": ',
								'value="', ( this.value ), '"',
								( this.disabled ? ', disabled' : '' )
							].join(''));
					}
					else
						content.push([
							'"', el.attr('name'), '": ',
							( this.checked ? 'checked' : 'not checked' ), 
							( this.disabled ? ', disabled' : '' )
						].join(''));
				});
				alert(content.join('\n'));
}
			
changeStyle = function(skin) {
	jQuery('#myform :checkbox').checkbox((skin ? {cls: skin} : {}));
}


/* Horizontal tab list
*
*----------------*/







var GUI = function() {
	function initGUI() {
	
		if ($.browser.msie && $.browser.version < 7)
		{MiscGUIFixes(false);}

		HideJavaScriptElements();
		$('img[src$=.png], .png').ifixpng();
		imageGallery();
		HorizontalTabList();
		infiniteSlider();
		tooltip();	//adds tooltip popup
		galleryTray();
		sliderGallery();
		datePicker();
		activateButtons();
					
		
	}
	

	function MiscGUIFixes(partialupdate) {
		HoverClassHelper('#mainNav > li', 'hover');
	}

	function HoverClassHelper(selector, cssclass) {
		$(selector).hover(

			function() { $(this).toggleClass(cssclass); },
			function() { $(this).toggleClass(cssclass); }
		);
	}
	
	function infiniteSlider() {
		
		if (document.images)
		{
		  //ctype1
		  //pic1= new Image(62,119); 
		  //pic1.src="images/common/carouselType1/nextBtnHover.jpg";
		  //pic2= new Image(62,119); 
		  //pic2.src="images/common/carouselType1/prevBtnHover.jpg";
		
		}
		if ( $(".infiniteCarousel").length > 0 ) 
		{ 
			$('.infiniteCarousel').infiniteCarousel();
			
		}
	}
	
	function galleryTray() {
	
	if ($('#dock2').length > 0){
		$('#dock2').Fisheye(
					{
						maxWidth: 28,
						items: 'a',
						itemsText: 'span',
						container: '.dock-container2',
						itemWidth: 72,
						proximity: 40,
						alignment : 'left',
						valign: 'bottom',
						halign : 'center'
					}
				)
	}
	
	}
	
	function activateButtons(){

		$('#headerCompare').click(function () {	
			$(".modalPopup").hide();		
			popPosition = $(this).position();			
			$('.mp_compareProducts').css({'display' : 'block', 'top' : (  156 + popPosition.top  + $(this).outerHeight()  ) , 'left' : ( popPosition.left - $('.mp_compareProducts').outerWidth() + $(this).outerWidth() )});
        });
		
		$('.email').click(function () {		
			$(".modalPopup").hide();
			popPosition = $(this).offset();
			contentPosition = $("#content").offset();
			$('.mp_sendToAFriend').css({'display' : 'block', 'top' : ( popPosition.top  + $(this).outerHeight()  ) , 'left' : ( popPosition.left - contentPosition.left - $('.mp_sendToAFriend').outerWidth() + $(this).outerWidth())});
        });
		
		$('.share').click(function () {		
			$(".modalPopup").hide();
			popPosition = $(this).offset();
			contentPosition = $("#content").offset();
			$('.mp_socialBookmarking').css({'display' : 'block', 'top' : ( popPosition.top  + $(this).outerHeight()  ) , 'left' : ( popPosition.left - contentPosition.left - $('.mp_socialBookmarking').outerWidth() + $(this).outerWidth())});
        });
		
		$('.datepickerInput').focus(function () {		
			$(".modalPopup").hide();
			window.currentDatepicker = $(this);
			popPosition = $(this).offset();
			contentPosition = $("#content").offset();
			$('.mp_smallCalendar').css({'display' : 'block', 'top' : ( popPosition.top  + $(this).outerHeight() - 90 ) , 'left' : ( popPosition.left - contentPosition.left - $('.mp_socialBookmarking').outerWidth() + $(this).outerWidth())});
        });
		
		$('.datepickerBtn').click(function () {		
			$(".modalPopup").hide();
			window.currentDatepicker = $(this).parent().find("input");
			popPosition = $(this).offset();
			contentPosition = $("#content").offset();
			$('.mp_smallCalendar').css({'display' : 'block', 'top' : ( popPosition.top  + $(this).outerHeight() - 90 ) , 'left' : ( popPosition.left - contentPosition.left - $('.mp_socialBookmarking').outerWidth() + $(this).outerWidth())});
        });
		
	}
	
	function datePicker() {

		if ( $(".datepicker").length > 0 ) {		

		Date.firstDayOfWeek = 0;
		Date.format = 'mm/dd/yyyy';
		
		$('.datepicker').datePicker({inline:true}).bind(
						'dateSelected',
						function(e, selectedDate, $td)
						{
							window.currentDatepicker.val('' + selectedDate.getDate() + '/' + selectedDate.getMonth() + '/' + selectedDate.getFullYear());
						}
					);
		}		
	}
	
	function sliderGallery() {
		
		if ($(".sliderGallery").length > 0){

				var container = $('.sliderGallery');
				var ul = $('.sliderGallery ul');
				//$(".sliderGallery ul").width(9999);				
				var itemsWidth = ul.innerWidth() - container.outerWidth();

								
			   $('.slider').slider({
					min: 0,
					max: itemsWidth,
					stop: function (event, ui) {
						ul.animate({'left' : ui.value * -1}, 500);					
					},
					slide: function (event, ui) {
						ul.css('left', ui.value * -1);					
					}
				}); 
			}
	}
	
	function HideJavaScriptElements() {
		$(".noJS").hide();
	}
	
	function HorizontalTabList() {
	
		$(".tlhButtonWrapper li").click(function () {
		
		$(".tlhButtonWrapper li").removeClass("tlhSelectedTrue")
		$(this).addClass("tlhSelectedTrue");

		$(".tlhContentWrapper").hide();
		$(".tlhContentWrapper").eq($(".tlhButtonWrapper li").index(this)).fadeIn(500);
		
        });

	}
	
	function tooltip() {
	
		tooltWidth = $(".mp_toolTip").width()/2;

		$(".toolTipSpan").bind("mousemove",function(e){
		  $(".mp_toolTip .toolTipText").html($(".toolTipInfo",this).html());
		  $(".mp_toolTip").css({'display' : 'block', 'top' : $(this).offset().top -6, 'left' : e.pageX - $("#content").offset().left - tooltWidth });
		}).bind("mouseleave",function(){
		  $(".mp_toolTip").css({'display' : 'none'});
		});
		$(".toolTipImg").bind("mousemove",function(e){
		  $(".mp_toolTip .toolTipText").html($(this).attr("alt"));
		  $(".mp_toolTip").css({'display' : 'block', 'top' : $(this).offset().top -6, 'left' : e.pageX - $("#content").offset().left - tooltWidth });
		}).bind("mouseleave",function(){
		  $(".mp_toolTip").css({'display' : 'none'});
		});
	
	}

	function imageGallery() {	
	
	var picIndex = 0;
	var nrOfPics = $(".customImagesContainer li").length -1;
	$(".galleryTotalImg").text(nrOfPics+1);

	
		$(".mpPrevBtn").click(function () {	
				if ( picIndex <= 0 ) { picIndex = nrOfPics; }
				else{ picIndex = picIndex -1;}
				currentImg = $(".customImagesContainer li").eq(picIndex);
				$(".customImagesContainer .selectedImg").css({'display' : 'none'});
				$(".selectedImg",currentImg).css({'display' : 'block'});
				$(".galleryCurrentImg").text(picIndex+1);
				$(".mp_imageGallery #galleryBigPic").html('<img src="'+ $("span",currentImg).text()  +'" alt="AEG" />');
		});
		$(".mpNextBtn").click(function () {
				if ( picIndex >= nrOfPics ) { picIndex = 0; }
				else{ picIndex = picIndex +1;}			
				currentImg = $(".customImagesContainer li").eq(picIndex);
				$(".customImagesContainer .selectedImg").css({'display' : 'none'});
				$(".selectedImg",currentImg).css({'display' : 'block'});
				$(".galleryCurrentImg").text(picIndex+1);
				$(".mp_imageGallery #galleryBigPic").html('<img src="'+ $("span",currentImg).text()  +'" alt="AEG" />');
		});
		
		
		$(".customImagesContainer li").click(function () {
				$(".mp_imageGallery").show();
				$("#overlay").show();
				$(".customImagesContainer .selectedImg").css({'display' : 'none'});
				$(".selectedImg",this).css({'display' : 'block'});
				$(".galleryCurrentImg").text(picIndex+1);
				$(".mp_imageGallery #galleryBigPic").html('<img src="'+ $("span",this).text()  +'" alt="AEG" />');
				picIndex = $(".customImagesContainer li").index(this)
		});
	
	
	}

	return {
		init: initGUI
	}
} ();


function mpPopdown(boxName) {

	boxName = "." + boxName;

	if (boxName == ".mp_imageGallery")
	{
		$("#overlay").hide();
		$(boxName).hide();
		$(".customImagesContainer .selectedImg").css({'display' : 'none'});
	}
	
	else
	{
		$(boxName).hide();
	}
}


$( document ).ready( function() {

	GUI.init(); 	
	
});
