// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INTERFACE.JS                                                                                                                                            //
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// @package Shopping Cidade do Porto 2011
// @author Pedro Gonçalves
// @copyright Copyright (c) Front.end 2011
// @version 1.0
// @access public
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var $j = jQuery.noConflict();
// ########################################################################################################################################################/
// #### PLAYER ############################################################################################################################################/
// ########################################################################################################################################################/
/*
 var so = null;
 var auto_play = 0;
 var play_time = 0;
 function getFlashMovie(movieName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[movieName] : document[movieName];
 }
 function musicPause(flash) {
 getFlashMovie(flash).musicPause(0);
 }
 function musicPlay(flash) {
 getFlashMovie(flash).musicPlay(0);
 }
 function getTime(flash) {
 getFlashMovie(flash).getTime(0);
 }
 function setTime(valor) {
 play_time = valor;
 }
 function setCookie(name, value, days) {
 if (days) {
 var date = new Date();
 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
 var expires = "; expires=" + date.toGMTString();
 }
 else
 var expires = "";
 document.cookie = name + "=" + value + expires + "; path=/";
 }
 function getCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for (var i = 0; i < ca.length; i++) {
 var c = ca[i];
 while (c.charAt(0) == ' ')
 c = c.substring(1, c.length);
 if (c.indexOf(nameEQ) == 0)
 return c.substring(nameEQ.length, c.length);
 }
 return 0;
 }
 function deleteCookie(name) {
 setCookie(name, "", -1);
 }
 $j(window).unload(function() {
 getTime('player');
 setCookie('play_time', play_time);
 setCookie('auto_play', auto_play);
 });
 $j(document).ready(function() {
 try {
 if ($j('#player').length > 0) {
 play_time = new String(getCookie('play_time'));
 auto_play = new String(getCookie('auto_play'));
 if (auto_play == 1) {
 $j('.player > a').addClass('pause');
 }
 var flashvars = {
 url_xml: endereco_site + '/media/mp3/',
 tempo: play_time,
 auto_play: auto_play
 };
 var params = {};
 var attributes = {};
 swfobject.embedSWF(endereco_site + '/media/mp3/player.swf', 'player', "1", "1", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
 $j('.player > a').live('click', function() {
 if (auto_play == 0) {
 musicPause('player');
 $j(this).addClass('pause');
 auto_play = 1;
 }
 else {
 musicPlay('player');
 $j(this).removeClass('pause');
 auto_play = 0;
 }
 });
 }
 }
 catch (o) {
 }
 });
 */
if (endereco_site == 'http://www.shoppingcidadedoporto.com') {
	$j(document).ready(function() {
		var pathname = $j(location).attr('href').replace(endereco_site, '');
		if (pathname == 'index.php' || pathname == '/index.php') {
			pathname = '';
		}
		window.parent.location = endereco_site + '/#' + pathname;
		window.parent.document.title = document.title;
	});
}
$j(document).ready(function() {
	try {
		if (window.parent.auto_play == 1) {
			$j('.player > a').addClass('pause');
		}
		$j('.player > a').live('click', function() {
			window.parent.playPause();
		});
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### CABEÇALHOS ########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		if ($j('#cabecalhos').length > 0) {
			var cabecalhosSlider = null;
			cabecalhosSlider = $j('#cabecalhos').bxSlider({
				mode: 'fade',
				controls: false,
				auto: true,
				speed: 1200,
				pause: 5000
			});
		}
		else {
			$j('#top').addClass('dark');
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### FOOTER ############################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		var margin = $j(document).height() - $j('body').height();
		if (margin > 0) {
			$j('.footer').css('margin-top', margin + 'px');
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### DESTAQUES #########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('.destaque > .more').hover(function() {
			$j(this).children('label').stop().animate({
				opacity: 1
			}, 250);
			$j(this).siblings('.imagem').children('.gray').stop().animate({
				opacity: 0
			}, 250);
		}, function() {
			$j(this).children('label').stop().animate({
				opacity: 0
			}, 250);
			$j(this).siblings('.imagem').children('.gray').stop().animate({
				opacity: 1
			}, 250);
		});
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### NOTÍCIAS ##########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('.noticia .texto .more').hover(function() {
			$j(this).children('label').stop().animate({
				opacity: 1
			}, 250);
		}, function() {
			$j(this).children('label').stop().animate({
				opacity: 0
			}, 250);
		});
		if ($j('.noticia .imagem ul#imagem').length > 0 && $j('.noticia .imagem ul#imagem > li').length > 1) {
			var noticiaSlider = null;
			noticiaSlider = $j('ul#imagem').bxSlider({
				mode: 'fade',
				controls: false,
				pager: true,
				speed: 800,
				auto: true,
				autoHover: true
			});
			$j('.noticia .imagem .bx-pager a').html('');
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### FANCYBOX ##########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('.produto > .imagem > a').fancybox({
			'opacity': true,
			'padding': 10,
			'overlayShow': true,
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'overlayColor': '#000000',
			'overlayOpacity': 0.6
		});
		$j('a.zoom').fancybox({
			'opacity': true,
			'titlePosition': 'inside',
			'padding': 10,
			'overlayShow': true,
			'transitionIn': 'elastic',
			'transitionOut': 'elastic',
			'overlayColor': '#000000',
			'overlayOpacity': 0.6
		});
		$j('a.zoomYoutube').fancybox({
			'titleShow': false,
			'transitionIn': 'fade',
			'transitionOut': 'fade',
			'type': 'swf',
			'swf': {
				'wmode': 'transparent',
				'allowfullscreen': 'true'
			}
		});
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### GALERIA ###########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		if ($j('#galeria').length > 0) {
			var galeriaSlider = null;
			galeriaSlider = $j('#galeria').bxSlider({
				mode: 'horizontal',
				infiniteLoop: false,
				easing: 'easeOutExpo',
				controls: true,
				prevText: '',
				nextText: '',
				hideControlOnEnd: true,
				auto: false,
				speed: 1000
			});
			$j('ul#galeria a').hover(function() {
				$j(this).children('span').stop().animate({
					opacity: 1
				}, 250);
			}, function() {
				$j(this).children('span').stop().animate({
					opacity: 0
				}, 250);
			});
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### LOJAS #############################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		if ($j('div.lojas').length > 0) {
			$j('div.lojas').jScrollPane({
				showArrows: true
			});
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### PESQUISA #############################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('#form_pesquisa > a').live('click', function() {
			$j('#form_pesquisa').submit();
		});
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### NEWSLETTER #############################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('#newsletter').live('focus', function() {
			var val = $j.trim($j(this).val());
			var rel = $j.trim($j(this).attr('rel'));
			if (val == rel) {
				$j(this).val('');
			}
		});
		$j('#newsletter').live('blur', function() {
			var val = $j.trim($j(this).val());
			var rel = $j.trim($j(this).attr('rel'));
			if (val == '') {
				$j(this).val(rel);
			}
		});
		$j('#form_newsletter > .submit').live('click', function() {
			$j('#form_newsletter').submit();
		});
		if ($j('#newsletterMsg').length > 0) {
			var top = $j('#newsletterMsg').offset().top;
			window.scrollBy(0, top);
			if ($j(this).attr('rel') == 'error') {
				$j('#newsletter').focus();
			}
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### MAPA ###########################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		if ($j('#map_canvas').length > 0) {
			var map = null;
			var directionDisplay;
			var directionsService = null;
			directionsService = new google.maps.DirectionsService();
			directionsDisplay = new google.maps.DirectionsRenderer();
			$j('#directions_panel').html('');
			$j('#map_canvas').html('');
			var lat = 41.154971;
			var lng = -8.629613;
			var zoom = 15;
			var titulo = 'Shopping Cidade do Porto';
			var myLatlng = new google.maps.LatLng(lat, lng);
			var myOptions = {
				zoom: parseFloat(zoom),
				center: myLatlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				panControl: true,
				zoomControl: true,
				zoomControlOptions: {
					style: google.maps.ZoomControlStyle.LARGE
				},
				streetViewControl: false
			}
			map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
			directionsDisplay.setMap(map);
			directionsDisplay.setPanel(document.getElementById("directions_panel"));
			var infowindow = new google.maps.InfoWindow({
				content: titulo
			});
			var contentString = '';
			contentString += '<div class="mapsContent">';
			contentString += '<img src="' + endereco_site + '/templates/images/mapsLogo.png" alt="Shopping Cidade do Porto" width="150" height="55" />';
			contentString += '<p>Rua Gonçalo Sampaio nº 350<br />4150-365 Porto</p>';
			contentString += '<p>Telefone 226 008 585</p>';
			contentString += '</div>';
			var infowindow = new google.maps.InfoWindow({
				content: contentString,
				maxWidth: 220
			});
			var marker = new google.maps.Marker({
				position: myLatlng,
				map: map,
				title: titulo,
				icon: endereco_site + '/templates/images/marker.png'
			});
			google.maps.event.addListener(marker, 'click', function() {
				infowindow.open(map, marker);
			});
			$j('.getMap').live('click', function() {
				var end = new google.maps.LatLng(lat, lng);
				var start = $j('#local').val();
				var request = {
					origin: start,
					destination: end,
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				directionsService.route(request, function(response, status) {
					if (status == google.maps.DirectionsStatus.OK) {
						directionsDisplay.setDirections(response);
					}
					else {
						alert('Não foi possível calcular o trajeto.');
					}
				});
			});
		}
	} 
	catch (o) {
	}
});
// ########################################################################################################################################################/
// #### ACÇÕES DO RODAPÉ ##################################################################################################################################/
// ########################################################################################################################################################/
$j(document).ready(function() {
	try {
		$j('.print').live('click', function() {
			print();
		});
		$j('.favoritos').live('click', function() {
			var currenturl = window.location;
			var currenttitle = document.title;
			try {
				if (window.sidebar) {
					window.sidebar.addPanel(currenttitle, currenturl, "");
				}
				else 
					if (window.external) {
						window.external.AddFavorite(currenturl, currenttitle);
					}
					else 
						if (window.opera && window.print) {
							alert('Funcionalidade não suportada pelo seu browser.\nPressione Ctrl + D para adicionar esta página aos seus favoritos.');
						}
						else {
							alert('Funcionalidade não suportada pelo seu browser.\nPressione Ctrl + D para adicionar esta página aos seus favoritos.');
						}
			} 
			catch (o) {
				alert('Funcionalidade não suportada pelo seu browser.\nPressione Ctrl + D para adicionar esta página aos seus favoritos.');
			}
		});
	} 
	catch (o) {
	}
});

