$(function() {
    
    if ($.browser.mozilla) {
        $('body').addClass('ff');
        if ($.browser.version == "1.9.1.9") {
            $('body').addClass('ff35');
        }
    }
    else if ($.browser.opera) {
        $('body').addClass('oo');
        //alert ($.browser.version);
    }
    else if ($.browser.safari) {
        $('body').addClass('sf');
    }
    else if ($.browser.msie) {
        if ($.browser.version == "6.0") {
            $('body').addClass('ie6');
        }
        else if($.browser.version == "7.0") {
            $('body').addClass('ie7');
        }
        else if($.browser.version == "8.0") {
            $('body').addClass('ie8');
        }
    }

});
var leftPad = 0;
var initWeirdGallery = function() {
	
	//$('.view-uc-products #viewscarousel-uc-products-block-1 li:first').addClass('activeThumb');
	
$('.prod_gallery_list li').click(function(e) {
	e.preventDefault();
	$('.prod_gallery_img img').attr('src', $(this).children('a').attr('href'));
	$('.prod_gallery_list li').removeClass('activeThumb');
	$(this).addClass('activeThumb');
	leftPad = ($('.prod_gallery_img').width() - $('.prod_gallery_img').children('img').width()) / 2 ;
	$('.prod_gallery_img img').css({left: leftPad});
	$('.reset').click()
});
	//$('.prod_gallery_list li:first').click();
}
var attachZoomListeners = function() { 
	var pic = $('.prod_gallery_img img');

	pic.removeAttr("width").removeAttr("height").css({ width: "auto", height: "auto" });

	var originalWidth = pic.width();
	var originalHeight = pic.height();
	pic.css('height', '300px');
	
	var heightIntervals = originalHeight / 3;
	//alert(heightIntervals)
	//console.debug(heightIntervals);
	
	$('.zoominout .zoomin').click(function(e) {
		e.preventDefault();
		//alert(heightIntervals)
		if ($('.zoominout').hasClass('zoomlevel0')) {
			pic.animate({height: (heightIntervals * 4)}, {queue: false, duration: 500, complete: function() {
				$('.prod_gallery_img img').bind('mousedown', function(e) {
					e.preventDefault();
					var mousex = e.pageX;
					var mousey = e.pageY;
					var originalTop = $('.prod_gallery_img img').position().top;
					var originalLeft = $('.prod_gallery_img img').position().left;
					
					$('.prod_gallery_img img').bind('mousemove', function(e) {
						e.preventDefault();
						var newmousex = e.pageX;
						var newmousey = e.pageY;
						$('.prod_gallery_img img').css({
							top: originalTop - (mousey - newmousey),
							left: originalLeft - (mousex - newmousex)
						});
						
						//console.debug('Mouse is down and moving!');
					});
				}).bind('mouseup', function(e) {
					e.preventDefault();
					$('.prod_gallery_img img').unbind('mousemove');
				});
			}});
			$('.zoominout').addClass('zoomlevel1').removeClass('zoomlevel0');
		}
		else if ($('.zoominout').hasClass('zoomlevel1')) {
			pic.animate({height: (heightIntervals * 5)}, {queue: false, duration: 500});
			$('.zoominout').addClass('zoomlevel2').removeClass('zoomlevel1');
		}
	});
	
	$('.zoominout .zoomout').click(function(e) {
		e.preventDefault();
		
		if ($('.zoominout').hasClass('zoomlevel1')) {
			pic.animate({height: 300}, {queue: false, duration: 500});
			$('.zoominout').addClass('zoomlevel0').removeClass('zoomlevel1');
			$('.prod_gallery_img img').unbind('mousedown mousemove');
			$('.prod_gallery_img img').animate({top: '63px', left: leftPad},{queue: false, duration: 300});
		}
		else if ($('.zoominout').hasClass('zoomlevel2')) {
			pic.animate({height: (heightIntervals * 4)}, {queue: false, duration: 500});
			$('.zoominout').addClass('zoomlevel1').removeClass('zoomlevel2');
		}
	});
	$('.reset').click(function(e) {
		e.preventDefault();
		pic.removeAttr("width").removeAttr("height").css({ width: "auto", height: "auto" });
		pic.css('height', '300px');
		leftPad = ($('.prod_gallery_img').width() - $('.prod_gallery_img').children('img').width()) / 2 ;
		$('.prod_gallery_img img').css({left: leftPad,top:'63px'});
		$('.zoominout').addClass('zoomlevel0').removeClass('zoomlevel1').removeClass('zoomlevel2');
			//pic.animate({height: 300}, {queue: false, duration: 500});
			//$('.zoominout').addClass('zoomlevel0').removeClass('zoomlevel1').removeClass('zoomlevel2');
			//$('.prod_gallery_img img').unbind('mousedown mousemove');
			//leftPad = ($('.prod_gallery_img').width() - $('.prod_gallery_img').children('img').width()) / 2 ;
			//$('.prod_gallery_img img').animate({top: '63px', left: leftPad},{queue: false, duration: 300});
		
	})
}



 $(document).ready(function() {
	 
//PRODUCT TABS
	 
	 
	 //--Input Newsletter focus 
	$('input#newsletter-mail').each(function(i, el) {
		var initialVal = $(el).val();
		$(el).focus(function() {
			if ($(this).val() == initialVal) {
				$(this).val("");
			}
		}).blur(function() {
			if ($(this).val() == "") {
				$(this).val(initialVal);
			}
		});
	}); 


	 //FILTERS
	$('.slideme h3').click(function(){
		$(this).parent().find('.filters').slideToggle()
		$(this).parent().find('.filterslong').slideToggle()
	})
	$('.ui-slider-handle:last').addClass('second')
	 
	if ($('body').hasClass('product')) {
		$("ul.tabs").tabs("div.panes > div");
		$("a[rel]").overlay({color: '#ccc',mask: '#7f7f7f'});   
	}
	$('div.sizefinder a').click(function(e){
		e.preventDefault()	
		$('.scroll-pane').jScrollPane()
	})
	
	try{
	$('.scroll').jScrollPane({showArrows: true});
	}
	catch(err){}





//-------------------//
//	
//	$('input#newsletter-mail').focus(function() {
//		if ($(this).val() == "type your email here") {
//			$(this).val("");
//		}
//	}).blur(function() {
//		if ($(this).val() == "") {
//			$(this).val("type your email here");
//		}
//	});
	
	$('div.languages ul li.active a').click(function(e) {
		e.preventDefault();
		$('div.languages ul li:eq(1)').css({
			display:	'block',
			position:	'absolute'
		});	
		
	});
	
	$('span.text2').each(function() {
		var height=$(this).height()
		//console.log(height)
		if (height>24){$(this).addClass('double')}					  
	});							  
	
	if($('#carousel').length>0){
		jQuery('#carousel').jcarousel();
	}
	if($('.homeslides').length>0){
		$('.homeslides').cycle({ 
		    fx:     'fade', 
		    delay:  -2000 
		});
	}
	
	//Left Toggle Menu
	$('.leftsidebar .leftmenu ul li.expanded ul').slideToggle();
	$('.leftsidebar .leftmenu ul li li.active,.leftsidebar .leftmenu ul li li.active-trail').parent('ul').slideToggle().addClass('open').parent().addClass('open') 	
	//$('#leftsidebar .leftmenu ul li.active-trail ul.open').slideToggle();
	$('.leftsidebar .leftmenu ul li.expanded > a').click(function (e) {
		e.preventDefault();
		if($(this).parent().children('ul').hasClass('open')) {
			$(this).parent().removeClass('open').children('ul').slideToggle().removeClass('open');
		}
		else {
			$('.leftsidebar .leftmenu ul.open').slideToggle().removeClass('open').parent().removeClass('open');
			$(this).parent().addClass('open').children('ul').slideToggle().addClass('open');
		}
	})
	
	
	

		
	//initWeirdGallery();
	//attachZoomListeners();
});

$(window).load(function() {
	if ($('body').hasClass('product')) {
		leftPad = ($('.prod_gallery_img').width() - $('.prod_gallery_img').children('img').width()) / 2;
		leftPad=leftPad - 22;
		$('.prod_gallery_img').css({width: $('.prod_gallery_img').width() - leftPad});
		$('.prod_gallery_img img').css({left: leftPad});
		
		initWeirdGallery();
		attachZoomListeners();
		$('.prod_gallery_list li:first').click();
	}
	try{
		initialize();
		}
		catch (err){}
})

function initialize() {
  var myLatlng = new google.maps.LatLng(37.93115,23.745039);
  var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  var image = 'images/marker.png';
  var myLatLng = new google.maps.LatLng(37.93115,23.745039);

  var beachMarker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      icon: image
  });
}

