$(document).ready(function() {

	$('.device_box a.handytest').tooltip({ 
    		track: true, 
    		delay: 0, 
    		showURL: false, 
    		showBody: " - ", 
		fade: 0 
	});


	$('a.fancybox').fancybox({
		'padding'             : 10,
		'titleShow' : true
	});

	$(".fancyboxIframe").fancybox({
		'padding' : 0,
		'width' : 720,
		'height' : 440,
		'autoScale' : false,
		'scrolling': 'no',
		'autoDimensions': false,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'type' : 'iframe',
		'titleShow' : false,
		'onClosed': function() {
			location.reload(true);
			$('#container_compare .more').html('Handyvergleich wird gestartet...');
		}
	});

	$("a.youtubeLink").click(function() {
                 $.fancybox({
                  'padding'             : 10,
                  'autoScale'   : 	false,
                  'transitionIn'        : 'none',
                  'transitionOut'       : 'none',
                  //'title'               : this.title,
                  'width'               : 680,
                  'height'              : 495,
                  'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                  'type'                : 'swf',    // <--add a comma here
                  'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here
                  });
                 return false;

        }); 

	var uagent = navigator.userAgent.toLowerCase();
	if ( uagent.indexOf('iphone') == -1 && uagent.indexOf('android') == -1 && uagent.indexOf('palm') == -1 && uagent.indexOf('webos') == -1 && uagent.indexOf('ipod') == -1 ) {
		if (screen.width > 700 && $("#navi_pinned").length > 0 ) {
			$(window).scroll(function () {
				   if($(window).scrollTop() >= 200) {
					$("#navi_pinned").fadeIn("fast");
				}
				else {
					$("#navi_pinned").fadeOut("fast");
				} 
			});
		}
	}

	$('.wrapper-unregistered').hover(function(e){
		$('.agent_unregistered',this).css('display', 'block');
	}, function(e){
		$('.agent_unregistered',this).css('display', 'none');
	});
	
	

	$('a#setProfilePic').click(function(e){
		e.preventDefault();
		$('#myagent_photos_upload_div').fadeIn('slow');
		document.location = document.location+'#uploadImage';
	});

	// ReplyComments
	var form	= '';
	var commentId	= '';
	$('.comment_list_inner a.reply').click(function(e){
		e.preventDefault();
		form	= $('form[name="commentForm"]');
		$(this).parent().parent().parent().next().next().children('.form-space').append(form).css('position', 'relative');
		$('div.cancel_reply a').css('display', 'block');
		commentId = $(this).attr('id').substr(6);
		$('input[name="we_ui_commentForm\\[commentParentId\\]"]').val(commentId);
		$('.comment_list').css('position', 'relative');
	});


	$('.cancel_reply a').click(function(e){
		e.preventDefault();
		$('a[name="comments"]').after($('form[name="commentForm"]'));
		$('div.cancel_reply a').css('display', 'none');
		$('input[name="commentParentId"]').val(0);
	});


	if ( $('#select_country_code_div').length > 0 ){
		$('#select_country_code_submit').live('click', function(){
			if( $(this).prev('select').val() == "0" ) return 0;

			var url_delimiter = (document.location.href.indexOf('?') == -1)? '?' : '&' ;
			document.location.href = document.location.href + url_delimiter + 'country_code=' + $(this).prev('select').val();
		});
	}

	// FILTER
	$('#filter_operating_system').change(function(){
		$('#form_filter_operating_system').submit();
	});



	$('.background-trigger-left, .background-trigger-middle').hover(
		function() {
			$(this).parent().css('background-image', 'url(/img/layout/bestpreis_kombi/kombi_privat.png)');
		},
		function() {
			$(this).parent().css('background-image', 'none');
		}
	);
	
	$('.background-trigger-right').hover(
		function() {
			$(this).parent().css('background-image', 'url(/img/layout/bestpreis_kombi/kombi_business.png)');
		},
		function() {
			$(this).parent().css('background-image', 'none');
		}
	);


	// Ersparnis Highlight
	$(".ersparnis_small").hover(
		function(){
			$(this).parent().children(".ersparnis_big").css('display', 'block');
		},
		function(){
			$(this).parent().children(".ersparnis_big").css('display', 'none');
		}
	);
	
	$(".ersparnis_big").hover(
		function(){
			$(this).css('display', 'block');
		},
		function(){
			$(this).css('display', 'none');
		}
	);

});


function isMobile(){
	if(navigator.userAgent!=null){
		var j=navigator.userAgent.toLowerCase();
		var n=["symbian","series60","series70","series80","series90","webos","240x320","vnd.rim","htc ","htc-","htc_","blackberry","nintendo","sonyericsson","ericsson","philips","sec-sgh","windows phone","windows ce","iemobile","kindle","playstation","wii","xbox","t-mobile","vodafone","vnd.wap","cldc-","midp","midp-2.0"," mmp/2.0","wap2.","xv6850","portalmmm","nook browser","palmos","mobileexplorer","opera mobi","android","opera mini","netfront","iphone;","heroc","; dream"];
		
		if(navigator&&navigator.platform&&screen&&screen.availWidth){var h=navigator.platform.toLowerCase();
			var m=screen.availWidth;if((h.indexOf("win32")>-1||h.indexOf("win64")>-1||h.indexOf("macppc")>-1||h.indexOf("macintel")>-1)&&m>800){return false;}
		}
		var k=false;
		for(var l=0;!k&&l<n.length;l++){
			k=(j.indexOf(n[l])>-1);
		}
		return k;
	}
	return false;
}

