// You may specify partial version numbers, such as "1" or "1.3",
//  with the same result. Doing so will automatically load the 
//  latest version matching that partial revision pattern 
//  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.1).
google.load("jquery", "1.6.4");
google.load("jqueryui", "1.8.16");

google.setOnLoadCallback(function() {
	$('.setCorner').corner();
	
	
	// innerFade
	$('#portfolio').innerfade({ 
		speed: 'slow', 
		timeout: 10000, 
		type: 'sequence', 
		containerheight: '45px' 
	});
	
	
	// Get latest 3 tweets by jQueryHowto
    $.jTwitter('SwissBankingSBA', 3, function(data){
        $('#twitterJQuery').empty();
        $.each(data, function(i, post){
            $('#twitterJQuery').append(
                '<div class="postTwitter">'
                +' <div class="txtTwitter">'
				+    '<div style="font-weight:bold;"><a href="http://twitter.com/#!/swissbankingsba" target="_blank" class="whiteLink">@' 
				+	 post.user.screen_name
				+    '</a></div><div style="height:80px; line-height:13px; overflow:hidden;">'
                +    setTwitterLink(post.text, '#fff')
				+    '</div>'
				+	 '<span style="font-style:italic;">' + setDate(post.created_at) + '</span>'
                +' </div>'
                +'</div>'
            );
        });
    });
	
	var border = '';
	var i = 0;
	
	// Get latest 3 tweets by jQueryHowto
    $.jTwitter('finews_ch', 3, function(data){
        $('#twitterFINEWS').empty();
        $.each(data, function(i, post){
        	border = '';
			i++;
			if(i < 3) 
		   	{	border += 'border-bottom:1px solid #00bae9; ';
			} 
			if(i > 1) 
			{	border += 'border-top:1px solid #fff;';
			}
			 $('#twitterFINEWS').append(
                '<div style="width:450px; padding:10px; '+ border +' height:54px;">'
                +' <div class="txtTwitter">'
				+    '<div style="float:left; margin-right:10px;"><a href="http://twitter.com/#!/finews_ch" target="_blank" class="whiteLink">' 
				+	 '<img src="'+post.user.profile_image_url+'" alt="finwes Logo">'
				+    '</a></div><div style="line-height:13px; height:30px; overflow:hidden; margin-bottom:5px;">'
                +    setTwitterLink(post.text, '#f00;') 
				+    '</div>'
				+	 '<span style="float:right; font-size:10px; font-style:italic;">' + setDate(post.created_at) + '</span>'
                +' </div>'
                +'</div>'
            );
        });
    });
	
	
	// Get Number of Followers on twitter
	$.ajax
	({	url: 'http://api.twitter.com/1/users/show.json',
		data: {screen_name: 'SwissBankingSBA'},
		dataType: 'jsonp',
		success: function(data) 
		{	$('#followers').html(data.followers_count + ' Follower');
		}
	});
	
	// Accordion
	$("html").addClass("js");
	$.fn.accordion.defaults.container = false; 
	$(function() {
	  $("#acc3").accordion({initShow : "#current"});
	  $("#acc1").accordion({
	      el: ".h", 
	      head: "h4, h5", 
	      next: "div" 
	     // initShow : "div.outer:eq(1)"
	  });
	  $("#acc2").accordion({
	      obj: "div", 
	      wrapper: "div", 
	      el: ".h", 
	      head: "h4, h5", 
	      next: "div", 
	      showMethod: "slideFadeDown",
	      hideMethod: "slideFadeUp",
	      initShow : "div.shown"
	    });
	  $("html").removeClass("js");
	});

});

/* Verlauf */
function setVerlauf()
{	var verlaufOutput = '';
	var verlauf = '';
	verlauf = verlauf.replace(/.htm/g, '');
	verlauf = verlauf.split('/');
	
	var x = 1;

	
	while(verlauf[x])
	{	if(x == 2)
		{	verlaufOutput += verlauf[x];
		} else if(x > 2 && verlaufOutput != '')
		{	verlaufOutput += ' » ' + verlauf[x];
		}
		x++;
	}
	
	document.write(verlaufOutput);
	
}


/* Twitter */
function setTwitterLink(text, color)
{	var link = text.search(/http:+/);
	link = text.substr(link, 20);
	if(link.search(/http:+/) != -1)
	{	text = text.replace(link, '<a class="whiteLink" style="color:'+color+';" href="'+link+'" target="_blank">'+link+'</a>');
	}
	return text;
}
/* Twitter */

function changeNewsPage(cont, page)
{	if(page > 0)
	{	var i = 1;
		while(document.getElementById(cont + i))
		{	document.getElementById(cont + i).style.display = 'none';
			document.getElementById(cont+'bubble_'+i).style.backgroundImage = 'url("boebelli-blau.png")';
			i++;
		}
		document.getElementById(cont + page).style.display = '';
		document.getElementById(cont+'bubble_'+page).style.backgroundImage = 'url("boebelli-wiss.png")';
	} else
	{	if(document.getElementById(cont + '1').style.display == 'none')
		{	document.getElementById(cont + '1').style.display = '';
			document.getElementById(cont + '2').style.display = 'none';
			document.getElementById(cont+'bubble_'+ '1').style.backgroundImage = 'url("boebelli-wiss.png")';
			document.getElementById(cont+'bubble_'+ '2').style.backgroundImage = 'url("boebelli-blau.png")';
		} else
		{	document.getElementById(cont + '2').style.display = '';
			document.getElementById(cont + '1').style.display = 'none';
			document.getElementById(cont+'bubble_'+ '2').style.backgroundImage = 'url("boebelli-wiss.png")';
			document.getElementById(cont+'bubble_'+ '1').style.backgroundImage = 'url("boebelli-blau.png")';
		}
	}
}


function setDate(date)
{	month = date.substr(4,3);
	day = date.substr(8,2);
	year = date.substr(26,4);
	
	if(month == 'Jan')
	{	month = 'Januar';
	} else if(month == 'Feb')
	{	month = 'Februar';
	} else if(month == 'Mar')
	{	month = 'März';
	} else if(month == 'Apr')
	{	month = 'April';
	} else if(month == 'May')
	{	month = 'Mai';
	} else if(month == 'Jun')
	{	month = 'Juni';
	} else if(month == 'Jul')
	{	month = 'Juli';
	} else if(month == 'Aug')
	{	month = 'August';
	} else if(month == 'Sep')
	{	month = 'September';
	} else if(month == 'Oct')
	{	month = 'Oktober';
	} else if(month == 'Nov')
	{	month = 'November';
	} else if(month == 'Dez')
	{	month = 'Dezember';
	}

	return day + ' ' + month + ' ' + year;
}


function switchArrow(element)
{	var up = element +'_up';
	var down = element +'_down';
	if(document.getElementById(up) && document.getElementById(down))
	{	if(document.getElementById(down).style.display == 'none')
		{	document.getElementById(down).style.display = '';
			document.getElementById(up).style.display = 'none';
		} else
		{	document.getElementById(down).style.display = 'none';
			document.getElementById(up).style.display = '';
		}
	}
}

function openDiv(element)
{	
	if(document.getElementById(element).style.display == 'none')
	{	document.getElementById(element).style.display = '';
	} else
	{	document.getElementById(element).style.display = 'none';
	}
}


/***** Blog *****/

function checkForm()
{	var stat = true;
	if(document.blog.titel.value == '')
	{	stat = false;
	}
	if(document.blog.sbvg_blog_kategorie.value == 0)
	{	stat = false;
	}
	if(document.blog.sbvg_blog_kontakt.value == 0)
	{	stat = false;
	}
	if(document.blog.LANGUAGE.value == 0)
	{	stat = false;
	}
	if(document.blog.sbvg_blog_status.value == 0)
	{	stat = false;
	}
	if(document.blog.objectID.value == 0)
	{	stat = false;
	}
	
	if(stat)
	{	document.getElementById('stat').value = 'submit';
		document.blog.submit();
	}
	else
	{	alert('</WEM>Bitte füllen Sie alle rot umrandeten Felder korrekt aus.');
	}
}

function saveBlog(id)
{	document.getElementById('editID').value= id;

	document.getElementById('editTitel').value= document.getElementById('titel-'+id).value;
	document.getElementById('editErfasser').value= document.getElementById('sbvg_blog_kontakt-'+id).value;
	document.getElementById('editKategorie').value= document.getElementById('sbvg_blog_kategorie-'+id).value;
	document.getElementById('editSprache').value= document.getElementById('LANGUAGE-'+id).value;
	document.getElementById('editStatus').value= document.getElementById('sbvg_blog_status-'+id).value;
	document.editBlog.submit();
}

function validEmail(email) 
{    var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
     var regex = new RegExp(strReg);
     return(regex.test(email));
}


function checkKommentarForm()
{	document.kommentar.text.style.border = '1px solid #A2A2A2';
	document.kommentar.name.style.border = '1px solid #A2A2A2';
	document.kommentar.mail.style.border = '1px solid #A2A2A2';

	var stat = true;
	if(document.kommentar.text.value == '' || document.kommentar.text.value == 'Schreiben Sie Ihren Kommentar hier.')
	{	stat = false;
		document.kommentar.text.style.border = '1px solid #EB1800';
	}
	if(document.kommentar.name.value == '' || document.kommentar.name.value == 'Vorname / Name')
	{	stat = false;
		document.kommentar.name.style.border = '1px solid #EB1800';
	}
	if(document.kommentar.mail.value == '')
	{	stat = false;
		document.kommentar.mail.style.border = '1px solid #EB1800';
	} else if(validEmail(document.kommentar.mail.value) == false)
	{	stat = false;
		document.kommentar.mail.style.border = '1px solid #EB1800';
	}
	if(document.kommentar.id.value == '')
	{	stat = false;
	}
	if(document.kommentar.agb.checked == false)
	{	if(stat)
		{	alert('Bitte akzeptieren Sie unsere Regeln.');
			return false;
		}
		stat = false;
	}

	if(stat)
	{	document.getElementById('stat').value = 'submit';
		document.kommentar.submit();
	}
	else
	{	alert('Bitte füllen Sie alle rot umrandeten Felder korrekt aus.');
	}
}

function changeYear(year)
{	var currentYear = Math.abs('2012')+1;
	while(!document.getElementById('tit-' + currentYear))
	{	currentYear--;
	}
	
	while(document.getElementById('tit-' + currentYear))
	{	document.getElementById('ct-' + currentYear).style.display = 'none';
		if(year != currentYear)
		{	document.getElementById('up-' + currentYear).style.display = 'none';
			document.getElementById('down-' + currentYear).style.display = '';
		}
		currentYear--;
	}
	
	
	
	if(document.getElementById('up-' + year).style.display == "none")
	{	document.getElementById('ct-' + year).style.display = '';
		document.getElementById('up-' + year).style.display = '';
		document.getElementById('down-' + year).style.display = 'none';	
	}
	else
	{	document.getElementById('up-' + year).style.display = 'none';
		document.getElementById('down-' + year).style.display = '';	
	}
}


/* Facebook */
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

/* Shop */

function popupWin(URLid) 
{	var URL = "shop_popup.htm?ID="+URLid;
	var name = "Drucksachen";
	var parameters = "toolbar=no,scrollbars=yes,directories=no,location=no,status=no,resizable=no,menubar=no,width=800,height=450,screenX=100,screenY=100";
	window.open(URL, name, parameters);
}

function openKat(id,anz)
{	//alert(id+","+anz)
	anz++;
	for (var a=1; a < anz; a++)
	{	if(document.getElementById('shopArt'+a))
		{	if(a == id)
			{	if(document.getElementById('shopArt'+a).style.display=='block')
				{	document.getElementById('shopArt'+a).style.display = 'none';
					document.getElementById('shopKatBut'+a).innerHTML = '<img src="arrow-down.png" alt="Arrow down" height="12" width="16">';
				} else
				{	document.getElementById('shopArt'+a).style.display = 'block';
					document.getElementById('shopKatBut'+a).innerHTML = '<img src="arrow-up.png" alt="Arrow down" height="12" width="16">';
				}
			}
			else
			{	document.getElementById('shopArt'+a).style.display = 'none';
				document.getElementById('shopKatBut'+a).innerHTML = '<img src="arrow-down.png" alt="Arrow down" height="12" width="16">';
			}
		}
	}

	
}

function checkShop()
{	var url= "shop.htm";
	var frmRef= document.forms.drucksachen;
		frmRef.action= url;
	
	frmRef.submit();	
	

}

/* Linkliste */

function changeLev(lev1,lev2)
{	//alert("Leve1: "+lev1+"; Level2: "+lev2);
	var a=1;
	var b=1;

	while(document.getElementById("lev"+a+"Tit"))
	{	if(a == lev1)
		{	document.getElementById("lev"+a+"Img").innerHTML= "<img src=\"arrow-up.png\">";
			document.getElementById("lev"+a+"Lev2").style.display= "block";
			b=1
			while(document.getElementById("lev"+a+"_"+b+"Tit"))
			{	//alert("lev"+a+"lev"+b+"lev3")
				if(b == lev2)
				{	document.getElementById("lev"+a+"_"+b+"Tit").style.display= "block";
					document.getElementById("lev"+a+"_"+b+"Img").innerHTML= "<img src=\"arrow-darkgray-up.png\">";
					if(document.getElementById("lev"+a+"lev"+b+"Lev3"))
					{	document.getElementById("lev"+a+"lev"+b+"Lev3").style.display= "block";
					}
				}
				else
				{	document.getElementById("lev"+a+"_"+b+"Tit").style.display= "block";
					document.getElementById("lev"+a+"_"+b+"Img").innerHTML= "<img src=\"arrow-darkgray-down.png\">";
					if(document.getElementById("lev"+a+"lev"+b+"Lev3"))
					{	document.getElementById("lev"+a+"lev"+b+"Lev3").style.display= "none";
					}
				}
				
				b++
			}
		}
		else
		{	document.getElementById("lev"+a+"Img").innerHTML= "<img src=\"arrow-down.png\">";
			document.getElementById("lev"+a+"Lev2").style.display= "none";
			while(document.getElementById("lev"+a+"_"+b+"Tit"))
			{	document.getElementById("lev"+a+"_"+b+"Tit").style.display= "none";
				if(document.getElementById("lev"+a+"lev"+b+"lev3"))
				{	document.getElementById("lev"+a+"lev"+b+"lev3").style.display= "none";
				}
				b++
			}
		}
		
		
		
		a++;
	}
	

}

function setKommentar(id, status)
{	document.getElementById('id').value = id;
	document.getElementById('status').value = status;
	document.editKommentare.submit();
}

/* Medienanlaesse Linkliste */

function changeMaLinks(sender)
{
	$(".maLinks").css("display", "none");
	$(sender).parent().parent().next(".maLinks").css("display", "block");
	$(".maLinksArrow .arrow-up").css("display", "none");
	$(".maLinksArrow .arrow-down").css("display", "block");
	$(sender).parent().find(".arrow-up").css("display", "block");
	$(sender).css("display", "none");
}

function makeVerlauf()
{
	 new CursorDivScroll( 'verlauf', 30, 5 );
}

function textCounter(field, maxlimit) 
{	if (field.value.length > maxlimit)
	{	var toTrimm= field.value.length -1;
		field.value = field.value.substring(0, toTrimm);
	}
}


