$.fn.myTimer = function(t,f){
    this.each(function(){setTimeout(f,t);});
    return this;
};

var leftPaging = {
	m: 3,
	current: 1,
	c: 0,	
	advanceLeftPaging: function()
	{
		var t = $(this).attr("rel").split("-");
		var p = t[1];		
		
		
		if(p == "next")
		{
			if(leftPaging.current < leftPaging.c)
			{
				leftPaging.current++;
			}
			else
			{
				return;
			}
		}
		else if(p == "prev")
		{
			if(leftPaging.current > 1)
			{
				leftPaging.current--;
			}
			else
			{
				return;
			}
		}
		else
		{
			leftPaging.current = parseInt(p);			 
			
		}
		
		var limit = (leftPaging.current-1) * leftPaging.m; 
		$(".left-event").hide();
		for(i = limit; i < limit+3; i++)
		{
			$(".left-event:eq(" + i + ")").show();
		}
	},
	init: function(){
		
		var c = $(".left-event").length;		
		
		if(c > 0)
		{
			leftPaging.c = Math.floor(c / leftPaging.m) + (c % leftPaging.m > 0 ? 1 : 0);
			
			$('<a href="javascript:;" rel="leftpaging-prev">&lt;</a>').bind('click', leftPaging.advanceLeftPaging).appendTo(".paging");
			$('<span>&nbsp;</span>').appendTo(".paging");
						
			for(i = 1; i <= leftPaging.c; i++)
			{
				$('<a href="javascript:;" rel="leftpaging-' + i + '">' + i + '</a>').bind('click', leftPaging.advanceLeftPaging).appendTo(".paging");
				$('<span>&nbsp;</span>').appendTo(".paging");
			}
			
			$('<a href="javascript:;" rel="leftpaging-next">&gt;</a>').bind('click', leftPaging.advanceLeftPaging).appendTo(".paging");
		}
		
		
		
	}
		
		
}





$().ready(function(){
	
	
	leftPaging.init();
	
});

function printPage() {
    var currentTime = new Date();
    var day = currentTime.getDate();
    if (day < 10){
        day = "0" + day;
    }
    var month = currentTime.getMonth() + 1;
    if (month < 10){
        month = "0" + month;
    }
    var year = currentTime.getFullYear();
    var hour = currentTime.getHours();
    if (hour < 10){
        hour = "0" + hour;
    }
    var minute = currentTime.getMinutes();
    if (minute < 10){
        minute = "0" + minute;
    }
    var printdate = day + "." + month + "." + year + " - " + hour + ":" + minute;
    var disp_setting = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=800, height=600, left=100, top=25";
    var content_value = document.getElementById("forprint").innerHTML;
    var docprint=window.open("","",disp_setting);
    docprint.document.open();
    docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="tr" lang="tr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>İKSV</title><link rel="stylesheet" href="css/print.css" type="text/css" media="screen,print"></head><body onLoad="self.print()"><div class="printwrap"><div class="printbox"><img src="/media/site/logo.png" alt="İKSV Logo" /><div class="printnote"><strong>'+document.title+'</strong><br />'+document.location.href+'<br />'+printdate+'</div></div><div class="printbox">');
    docprint.document.write(content_value);
    docprint.document.write('</div></body></html>');
    docprint.document.close();
    docprint.focus();
}

function SearchSubmit(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;  //IE
     else
          key = e.which;     //firefox
     if(key == 13) {
    	 $('#searchform').attr('action',$('#searchform').attr('action')+'/'+$('#searchkeyword').val());
         $("#searchform").submit();
     }
     else
          return true;
}



function SubmitSearchForm(puri, pkey, ppageno)
{
     uri = puri+'/'+pkey+'/'+ppageno;
     $('#searchkeyword').val(pkey);
     $('#pageno').val(ppageno);
     $('#searchform').attr('action',uri);
     $("#searchform").submit();
}

function setPlaceholder(id) {
    if (id.val()=="" && id.attr("placeholder")!=""){
        id.val(id.attr("placeholder"));
        id.focus(function(){
            if (id.val()==id.attr("placeholder"))
                id.val("");
        });
        id.blur(function(){
            if (id.val()=="")
                id.val(id.attr("placeholder"));
        });
    }
}

IKSV = {
    share : {
        email : {
            relocate : function () {
                var wH = $(window).height();
                var wW = $(window).width();
                if (wH > 175) {
                    $('#sendToFriendPopup').css({'top':(wH-175)/2});
                }
                if (wW > 247) {
                    $('#sendToFriendPopup').css({'left':(wW-247)/2});
                }
            },
            show : function () {
                $('#sendToFriendPopup').show();
            },
            hide : function () {
                $('#sendToFriendError').html('');
                $('#sendToFriendPopup').hide();
                $('#sendToFriendPopup input[type=text]').val('');
            },
            send : function () {
                $('#sendToFriendLoader').show();
                $.ajax({
                    type: 'POST',
                    url: '/Process.php',
                    data: {op: 'sendtofriend', email: $('#sendToFriendEmail').val(), name: $('#sendToFriendName').val(), sender: $('#sendToFriendSenderName').val(), link: $('#sendToFriendLink').val()},
                    dataType: 'json',
                    cache: true,
                    success: function(data) {
                        if (data.success) {
                            IKSV.share.email.hide();
                            $('#sendToFriendLoader').hide();
                        } else {
                            $('#sendToFriendError').html(eval(data.message));
                            $('#sendToFriendError').show();
                            $('#sendToFriendLoader').hide();
                        }
                    },
                    error: function(xhr, status, error) {
                        $('#sendToFriendError').html(unexpectederror);
                        $('#sendToFriendError').show();
                        $('#sendToFriendLoader').hide();
                    }
                });
                return false;
            }
        }
    },
    paging : function () {
        $('div.left-side img#scroller').hide();
    }
}

$(document).ready(function(){
    setPlaceholder($('#sendToFriendSenderName'));
    setPlaceholder($('#sendToFriendName'));
    setPlaceholder($('#sendToFriendEmail'));
    IKSV.share.email.relocate();
    $('div.share a.sendtofriend').bind('click',IKSV.share.email.show);
    $('#sendToFriendPopup a.close').bind('click',IKSV.share.email.hide);
    $('#sendToFriendSubmit').bind('click',IKSV.share.email.send);
    $('div.left-side p.paging > a').bind('click',IKSV.paging);
    
    Cufon.replace('a#language', {
            fontFamily: 'scala',hover: {color:'#999'}
    });
    Cufon.replace('ul#genre li', {
            fontFamily: 'scala-black'
    });
    Cufon.replace('ul#section li.main a.main', {
            fontFamily: 'scala',hover: {color:'#999'}
    });
    Cufon.replace('ul#building li', {
            fontFamily: 'scala',hover: {color:'#666'}
    });
    Cufon.replace('span#building-title', {
            fontFamily: 'scala'
    });
    Cufon.replace('ul#left-menu li.main a.main', {
            fontFamily: 'scala',hover: {color:'#999'}
    });
    Cufon.replace('span.day', {
            fontFamily: 'scala'
    });
    Cufon.replace('.skin-slidedeck dl.slidedeck > dd h1', {
            fontFamily: 'scala'
    });
    Cufon.replace('.skin-slidedeck dl.slidedeck > dd p', {
            fontFamily: 'scala'
    });
    Cufon.replace('span.page-title', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.right-side div.menu li.main a.main', {
            fontFamily: 'scala',hover: {color:'#999'}
    });
    Cufon.replace('div.left-side div.titles h2', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.left-side div.years h2', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.left-side div.special-events h2', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.left-side div.tabs h2', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.left-side div.steps h2', {
            fontFamily: 'scala'
    });
    Cufon.replace('div.error-page h1', {
            fontFamily: 'scala'
    });
    Cufon.replace('div..error-page a', {
            fontFamily: 'scala'
    });
    Cufon.replace('a.venicelink', {
            fontFamily: 'scala'
    });

    //SHORTEN SUB-PAGE HEADERS
    if ($('div.left-side span.page-title').text().length > 20)
        $('div.left-side span.page-title').css('font-size','32px');

    //PRINT
    $("a#print").click(function() {
        printPage();
    });

    //SEARCH BOX
    var searchBox = $("div#search input[type=text]");
    var searchBoxText = searchBox.attr("value");
    searchBox.focus(function() {
        if (searchBox.attr('value') == searchBoxText) {
            searchBox.attr("value", "");
        }
    });
    searchBox.blur(function() {
        if (searchBox.attr('value') == "") {
            searchBox.attr("value", searchBoxText);
        }
    });

    //SUB SECTION MENUS
    $("ul#section ul.sub li.sub").hover(function() {
        $(this).children("a").css({"color":"#999"});
        Cufon.refresh('ul#section li.main');
	},function() {
        $(this).children("a").css({"color":"#000"});
        Cufon.refresh('ul#section li.main');
	});
    $("ul#left-menu ul.sub li.sub").hover(function() {
        $(this).children("a").css({"color":"#999"});
        Cufon.refresh('ul#left-menu li.main');
	},function() {
        $(this).children("a").css({"color":"#000"});
        Cufon.refresh('ul#left-menu li.main');
	});
    $("div.right-side div.menu ul.sub li.sub").hover(function() {
        $(this).children("a").css({"color":"#999"});
        Cufon.refresh('div.right-side div.menu li.main');
	},function() {
        $(this).children("a").css({"color":"#000"});
        Cufon.refresh('div.right-side div.menu li.main');
	});
    $("ul#section ul.sub li.sub,ul#left-menu ul.sub li.sub,div.right-side div.menu ul.sub li.sub").click(function() {
        var targetLinkElement = $(this).children('a');
        if (targetLinkElement.attr('target')!='_blank')
            window.location.replace(targetLinkElement.attr("href"));
    });

    //TODAY
    if ($("div#today").length != 0) {
        var targetDiv = "div#slidedeck_frame";
        if (!$("div#slidedeck_frame")[0]) {
            targetDiv = "div#container";
        }
        $("div#today").css("left", $(targetDiv).offset().left - 48 + "px");
        $(window).resize(function() {
            $("div#today").css("left", $(targetDiv).offset().left - 48 + "px");
        });
        $('div#today a:not(.popup)').hover(function() {
            $(this).prev().css({"margin-left":"37px"});
            $(this).prev().css({"display":"block"});
        },function() {
            $(this).prev().css({"display":"none"});
        });
        $('div#today a.popup').mouseover(function() {
            $(this).css({"display":"block"});
        });
        $('div#today a.popup').mouseout(function() {
            $(this).css({"display":"none"});
        });
    }

    //QUICKLINK
    $("div.quicklink a:first").css({"margin-left":"8px"});
    $("div.quicklink a.pin,div.quicklink a.buy,div.quicklink a.unpin").hover(function() {
        switch ($(this).text()) {
            case "takvime ekleyin":$a = "0px";break;
            case "bilet al":$b = "-96px";break;
            case "add to calendar":$a = "-192px";break;
            case "takvimden çıkarın":$a = "-384px";break;
            case "remove from calendar":$a = "-480px";break;
            default:$b = "-288px";
        }
        $(this).parent().css({"margin-top":"-66px"});
        if ($(this).attr("class") == "buy") {
            $("div.quicklink div.description").css({"background-position":$b+" 0px"});
            $("div.quicklink div.line").css({"background-position":"-96px -20px"});
        } else if ($(this).attr("class") == "pin") {
            $("div.quicklink div.description").css({"background-position":$a+" 0px"});
        } else if ($(this).attr("class") == "unpin") {
            $("div.quicklink div.description").css({"background-position":$a+" 0px"});
        }
        $("div.quicklink div.description").css({"display":"block"});
        $("div.quicklink div.line").css({"display":"block"});
    },function() {
        $(this).parent().css({"margin-top":"-32px"});
        $("div.quicklink div.description").css({"display":"none"});
        $("div.quicklink div.line").css({"display":"none"});
        if ($(this).attr("class") == "buy") {
            $("div.quicklink div.description").css({"background-position":"0px 0px"});
            $("div.quicklink div.line").css({"background-position":"0px -20px"});
        }
    });

    //MEMO-TICKER
    if ($("div#memo-ticker").length != 0) {
        var childCount = $("div#memo-ticker > ul").children().length;
        var current = 1;
        var last = 0;
        var inAction = 0;
        var mtop = $("div#memo-ticker > ul").margin().top;
        var timer = setInterval(function() {goNext();}, 8000);
        function checkClass(childNo) {
            var className = $("div#memo-ticker > ul li:nth-child("+childNo+")").attr("class");
            $("div#memo-ticker").removeClass();
            if (className=="movie" || className=="theater" || className=="music" || className=="jazz" || className=="biennial" || className=="design" || className=="black") {
                $("div#memo-ticker").addClass(className);
            }
        }
        checkClass(1);
        function goPrev() {
            inAction = 1;
            if (current!=1) {
                current--;
                mtop += 35;
                $("div#memo-ticker > ul span").fadeOut('fast', function() {
                    $("div#memo-ticker > ul").margin({top:mtop});
                });
                $("div#memo-ticker > ul span").fadeIn(function() {
                    inAction = 0;
                });
                checkClass(current);
            } else {
                current = childCount;
                mtop = -(35*childCount)+35;
                $("div#memo-ticker > ul span").fadeOut('fast', function() {
                    $("div#memo-ticker > ul").margin({top:mtop});
                });
                $("div#memo-ticker > ul span").fadeIn(function() {
                    inAction = 0;
                });
                checkClass(current);
            }
        }
        function goNext() {
            inAction = 1;
            if (current!=childCount) {
                current++;
                mtop -= 35;
                $("div#memo-ticker > ul span").fadeOut('fast', function() {
                    $("div#memo-ticker > ul").margin({top:mtop});
                });
                $("div#memo-ticker > ul span").fadeIn(function() {
                    inAction = 0;
                });
                checkClass(current);
            } else {
                current = 1;
                mtop = 0;
                $("div#memo-ticker > ul span").fadeOut('fast', function() {
                    $("div#memo-ticker > ul").margin({top:mtop});
                });
                $("div#memo-ticker > ul span").fadeIn(function() {
                    inAction = 0;
                });
                checkClass(current);
            }
        }
        $("div#memo-ticker a.prev").click(function() {
            if (inAction == 0) {
                goPrev();
                clearInterval(timer);
                setTimeout(function() {timer = setInterval(function() {goNext();}, 8000);}, 500);
            }
        });
        $("div#memo-ticker a.next").click(function() {
            if (inAction == 0) {
                goNext();
                clearInterval(timer);
                setTimeout(function() {timer = setInterval(function() {goNext();}, 8000);}, 500);
            }
        });
        
        $("body").myTimer(100,function(){
            $("div#memo-box").hide();
        });
        $("div#memo-ticker > ul").click(function() {
            //clearInterval(timer);
            $("div#memo-box").show();
        });
        $("div#memo-box-header a").click(function() {
            $("div#memo-box").hide();
            //setTimeout(function() {timer = setInterval(function() {goNext();}, 4000);}, 500);
        });
        $("div#memo-box .scroll-pane ul li:nth-child(2n+1)").addClass('odd');
        $(function() {
            $('div#memo-box .scroll-pane').jScrollPane();
        });
    }

    //NEWSLETTER
    function arrowPosition () {
        $("div.tip-box-arrow").each(function(index) {
            var tipContentWidth = $(this).parent(".tip-box").width();
            var tipArrowMargin = tipContentWidth/2 - 8;
            $(this).css("margin-left",tipArrowMargin+"px");
        });
    }
    arrowPosition();
    var newsletterBox = $("div#newsletter input[type=text]")
    var newsletterBoxText = newsletterBox.attr("value");
    newsletterBox.focus(function() {
        $(this).parents("#newsletterfrm").siblings(".tip-box").css("display", "block");
        if (newsletterBox.attr('value') == newsletterBoxText) {
            newsletterBox.attr("value", "");
        }
    });
    newsletterBox.blur(function() {
        $("div.tip-box-c").html($("div#newsletter input[type=hidden]").attr("value"));
        arrowPosition();
        $(this).parents("#newsletterfrm").siblings(".tip-box").css("display", "none");
        if (newsletterBox.attr('value') == "") {
            newsletterBox.attr("value", newsletterBoxText);
        }
    });

    //POPUPS & CUFON :hover -> bold
    $("ul#building a").hover(function(e){
        $(this).siblings("img").css("display", "block");
    },  function() {
        $(this).siblings("img").css("display", "none");
    });

    //NEWS
    function animateNews(_holder,_multiplier,_columnWidth) {
        var holder = _holder;
        var multiplier = _multiplier;
        var columnWidth = _columnWidth;
        var newsCount = $(holder+" div#wheel > div").size();
        var wheelWidth = newsCount*columnWidth;
        var moveLimit = (newsCount - multiplier)*columnWidth;
        $(holder+" div#wheel").css("width", wheelWidth+"px");
        $(holder+" a.control").css("display", "block");
        var currentPos = 0;
        $(holder+" a.prev").click(function() {
            if (currentPos == 0) {
                $(holder+" div#wheel").animate({"margin-left":"-="+moveLimit+"px"}, "slow");
                currentPos = -moveLimit;
            }	else {
                if (currentPos > 0) {
                    currentPos -= columnWidth;
                    $(holder+" div#wheel").animate({"margin-left":"+="+columnWidth+"px"}, "slow");
                }	else {
                    currentPos += columnWidth;
                    $(holder+" div#wheel").animate({"margin-left":"+="+columnWidth+"px"}, "slow");
                }
            }
        });
        $(holder+" a.next").click(function() {
            if (currentPos == -moveLimit) {
                $(holder+" div#wheel").animate({"margin-left":"0px"}, "slow");
                currentPos = 0;
            }	else {
                if (currentPos <= 0) {
                    currentPos -= columnWidth;
                    $(holder+" div#wheel").animate({"margin-left":"-="+columnWidth+"px"}, "slow");
                }	else {
                    currentPos += columnWidth;
                    $(holder+" div#wheel").animate({"margin-left":"+="+columnWidth+"px"}, "slow");
                }
            }
        });
    }
    if ($("div#news-holder").length != 0 && $("div#news-holder div#wheel > div").size() > 3) {
        animateNews("div#news-holder",3,220);
    } else if ($("div#related-news").length != 0 && $("div#related-news div#wheel > div").size() > 4) {
        animateNews("div#related-news",4,132);
    }

    //SOCIALMEDIA
    $("div#socialmedia a#f,div#socialmedia a#t").hover(function() {
        if ($(this).attr("id") == "t") {
            $(this).parent().css({"background-position":"-57px 0px"});
        }
        $(this).parent().css({"background-image":"url('media/site/socialmedia.jpg')"});
    },function() {
        $(this).parent().css({"background":"none"});
    });

    //CALENDAR-LINK
	/*
    $(window).resize(function() {
        var windowHeight = $(window).height();
        var calendarTop = windowHeight - 70;
        $("div#calendar-holder").css({'top':+calendarTop + $(window).scrollTop()+"px"});
    });
    $(window).scroll(function() {
        var windowHeight = $(window).height();
        var calendarTop = windowHeight - 70;
        $("div#calendar-holder").css({'top':+calendarTop + $(window).scrollTop()+"px"});
    });
	*/
    $("a.calendar-close").click(function() {
        $("div#calendar-holder").fadeOut();
        $("a#calendar-open").fadeIn();
    });
    $("a#calendar-open").click(function() {
        $(this).fadeOut();
        $("div#calendar-holder").fadeIn();
    });

    //SHARE MENU
    if ($('div.share').length != 0) {
        /*
        $("a#share").toggle(function() {
            $(this).css({"background-position":"-115px -23px"});
            $("img.indicator").css({"display":"block"});
            $(this).parents("div").siblings("div.down").delay(300).stop().animate({"right":"145px"}, "slow");
        }, function() {
            $(this).css({"background-position":"-115px 0px"});
            $(this).removeAttr("style");
            $(this).parents("div").siblings("div.down").stop().animate({"right":"0px"}, "slow", function(){
                 $("img.indicator").css({"display":"none"});
            });
        });
        */
        var textSize = 0;
        $("a#enlarge").click(function() {
            if (textSize < 3) {
                textSize++;
            } else {
                textSize = 0;
            }
            switch (textSize) {
                case 1:
                    $div = "14px";
                    $h1 = "16px";
                    $p = "14px";
                    break;
                case 2:
                    $div = "16px";
                    $h1 = "18px";
                    $p = "16px";
                    break;
                case 3:
                    $div = "18px";
                    $h1 = "20px";
                    $p = "18px";
                    break;
                default:
                    $div = "12px";
                    $h1 = "14px";
                    $p = "12px";
            }
            $("div#container div.content").css({"font-size":$div});
            $("div#container div.content h1").css({"font-size":$h1});
            $("div#container div.content p").css({"font-size":$p});
        });
        //$("div.right-side div.content h1").css({"margin-top":"0"});
    }

    //LEFT ARCHIVE TITLE LIST (HISTORY PAGE)
    if ($('div.titles').length != 0) {
        showChild(0);
        $("div.titles").myTimer(500,function(){
            $("div.titles div:first").addClass("selected");
            $ownHeight = $("div.titles div:first").height()/2;
            $("img#scroller").css({"top":$("div.selected").position().top+$ownHeight+"px"});
        });
        $("div.titles").children().not("#scroller").click(function() {
            if (!$(this).hasClass('selected')) {
                $("div.selected").removeClass("selected");
                $(this).addClass("selected");
                $ownHeight = $(this).height()/2;
                $("img#scroller").stop().animate({"top":$("div.selected").position().top+$ownHeight+"px"}, "slow");
                showChild($(this).index()-1); //-1 scroller img
            }
            //window.location.replace($(this).children('h2').children('a').attr("href"));
        });
    }
    
    //LEFT YEAR LIST
    if ($('div.years').length != 0) {
        $('div.left-side .accordionContent').hide();
        $("div.years").myTimer(500,function(){
            if ($('div.left-side .accordionButton.on').length==0) {
                $('div.left-side .accordionButton:first').addClass('on');
                $('div.left-side .accordionButton:first').next().slideDown('normal');
            } else {
                $('div.left-side .accordionButton.on').next().slideDown('normal');
            }
            if ($('div.left-side .accordionContent li.selected').length==0)
                $('div.left-side .accordionContent:first li:first').addClass('selected');
            $ownHeight = $("li.selected").height()/2-8;
            $("img#scroller").css({"top":$("li.selected").position().top+$ownHeight+"px"});
            $currentHeaderWas = $("div.on").text();//scroller görselinin hangi başlık altında bulunduğunu hatırlamak için kullanıyoruz
            Cufon.refresh('div.left-side div.years h2');
        });
        $('div.left-side .accordionButton').click(function() {
            if (!$(this).hasClass('on')) {
                if ($currentHeaderWas == $(this).text()) {
                    $("img#scroller").css({"display":"block"});
                } else {
                    $("img#scroller").css({"display":"none"});
                }
                $('div.left-side .accordionButton').removeClass('on');
                $('div.left-side .accordionContent').slideUp('normal');
                if($(this).next().is(':hidden') == true) {
                    $(this).addClass('on');
                    $(this).next().slideDown('normal');
                }
            }
            Cufon.refresh('div.left-side div.years h2');
        });
        $('div.left-side .accordionContent li').click(function() {
            /* ---scroller animations---
            if (!$(this).hasClass('selected')) {
                
                $("li.selected").removeClass("selected");
                $(this).addClass("selected");
                $ownHeight = $(this).height()/2-8;
                if ($currentHeaderWas != $("div.on").text()) {
                    $currentHeaderWas = $("div.on").text();
                    $("img#scroller").css({"top":$(this).position().top+$ownHeight+"px"});
                    $("img#scroller").css({"display":"block"});
                } else {
                    $("img#scroller").stop().animate({"top":$(this).position().top+$ownHeight+"px"}, "slow");
                }
            }*/
            window.location.replace($(this).children('h3').children('a').attr("href"));
        });
    }

    //NAVIGATION WITH #
    var pageurl = document.location.href;
    var section = pageurl.substring(pageurl.length,pageurl.length-1);

    //EXEPTIONS!!!
    var exception = 0;
    var last10char = pageurl.substring(pageurl.length,pageurl.length-10);
    if (last10char == "viyana2009" || last10char == "viyana2008" || last10char == "vienna2009" || last10char == "vienna2008") {exception=1;}

    if ($('div.sharable').length != 0) {
        $div = "";$h2 = "";$rel="";
        if ($('div.tabs').length != 0) {$div = "div.tabs div.tabMenu";$h2 = " h2";}
        if ($('div.special-events').length != 0) {$div = "div.special-events";}
            $($div+" div"+$h2+" a").each(function() {
                $(this).attr("href",pageurl+"#"+$(this).attr("rel"));
            });
            $($div+" div").click(function() {
                if (IsNumeric(section)) {$modifiedurl = pageurl.substring(0,pageurl.length-2);} else {$modifiedurl = pageurl;}
                if ($div == "div.special-events") {
                    $getid = $(this).children("a").attr("id");
                    $id = $getid.split("-");
                    $coreurl = 'http://'+window.location.hostname;
                    if (pageurl.search("ozeletkinlikler")==-1) {$coreurl += "/en/specialevents"} else {$coreurl += "/tr/ozeletkinlikler"}
                    $("div.share a.facebook").attr("href","http://www.facebook.com/share.php?u="+$coreurl+"/id/"+$id[1]);
                    $("div.share a.twitter").attr("href","http://twitter.com/home?status="+$("title").text()+"%20"+$coreurl+"/id/"+$id[1]);
                    $("div.share a.friendfeed").attr("href","http://www.friendfeed.com/share?title="+$("title").text()+"&link="+$coreurl+"/id/"+$id[1]);
                    $("div.share a.stumbleupon").attr("href","http://www.stumbleupon.com/submit?url="+$coreurl+"/id/"+$id[1]);
                } else if ($div == "div.tabs div.tabMenu") {
                    $("div.share a.facebook").attr("href","http://www.facebook.com/share.php?u="+$modifiedurl+"/"+$(this).children('h2').children('a').attr('rel'));
                    $("div.share a.twitter").attr("href","http://twitter.com/home?status="+$("title").text()+"%20"+$modifiedurl+"/"+$(this).children('h2').children('a').attr('rel'));
                    $("div.share a.friendfeed").attr("href","http://www.friendfeed.com/share?title="+$("title").text()+"&link="+$modifiedurl+"/"+$(this).children('h2').children('a').attr('rel'));
                    $("div.share a.stumbleupon").attr("href","http://www.stumbleupon.com/submit?url="+$modifiedurl+"/"+$(this).children('h2').children('a').attr('rel'));
                }
            });
    }
    
    //LEFT TAB LIST
    function showChild(i) {
		if(!$('div.content').hasClass('skipautoshow'))
		{
        	$("div.content").children("div").css({"display":"none"});
        	$("div.content").children("div:eq("+i+")").css({"display":"block"});
		}
        //accreditation form submit
        if ($("input#optresult").length != 0) {
            $("div.content").children("div").css({"display":"none"});
            $("div.right-side div.content").append('<div class="form-message"><p><b>'+ACCREDITATIONFORM+'</b><br />'+$("input#optresult").val()+'</p><a>'+aclose+'</a></div>');
            $("input#optresult").remove();
        }
    }
    function IsNumeric(input){
        var RE = /^-{0,1}\d*\.{0,1}\d+$/;
        return (RE.test(input));
    }
    if ($('div.tabs').length != 0) {
        if (IsNumeric(section) && exception==0) {showChild(section-1);} else {showChild(0);}
        $("div.tabs").myTimer(500,function(){
            if (IsNumeric(section) && exception==0) {$which="eq("+(section-1)+")";} else {$which="eq(0)"}
            $("div.tabMenu div:"+$which).addClass("selected");
            $ownHeight = $("div.tabMenu div:"+$which).height()/2;
            $("img#scroller").css({"top":$("div.selected").position().top+$ownHeight+"px"});
        });
        $("div.tabMenu").children().click(function() {
            if (!$(this).hasClass('selected')) {
                if ($('div.form-message').length != 0) {$('div.form-message').remove();}
                $("div.selected").removeClass("selected");
                $(this).addClass("selected");
                $ownHeight = $(this).height()/2;
                $("img#scroller").stop().animate({"top":$("div.selected").position().top+$ownHeight+"px"}, "slow");
                showChild($(this).index());
                if ($('div.sharable').length != 0) {window.location.replace($(this).children('h2').children('a').attr("href"));}
            }
        });
    }

    //LEFT SPECIAL-EVENT LIST
    if ($('div.special-events').length != 0) {
        /*
        $("div.special-events").myTimer(500,function(){
            $("div.special-events div:first").addClass("selected");
            $ownHeight = $("div.special-events div:first").height()/2;
            $("img#scroller").css({"top":$("div.selected").position().top+$ownHeight+"px"});
        });
        $("div.special-events").children().not("#scroller").click(function() {
            window.location.replace($(this).children('a').attr("href"));
        });
        */
        $findtab = pageurl.substring(pageurl.length,pageurl.length-5);
        $tab = $findtab.substring($findtab,3);
        if ($tab == "tab") {showChild(section-1);} else {
            if ($("div.autoshow").length != 0) {
                showChild($("div.autoshow").index()-1);
            } else {showChild(0);}
        }
        $("div.special-events").myTimer(500,function(){
            if ($tab == "tab") {$which="eq("+(section-1)+")";} else {
                if ($("div.autoshow").length != 0) {
                    $indexint = $("div.autoshow").index()-1;
                    $which="eq("+$indexint.toString()+")";
                } else {$which="eq(0)";}
            }
            $("div.special-events div:"+$which).addClass("selected");
            $ownHeight = $("div.special-events div:"+$which).height()/2;
            $("img#scroller").css({"top":$("div.selected").position().top+$ownHeight+"px"});
        });
        $("div.special-events").children('div').click(function() {
            if (!$(this).hasClass('selected')) {
                $('div.left-side img#scroller').show();
                if ($('div.form-message').length != 0) {$('div.form-message').remove();}
                $("div.selected").removeClass("selected");
                $(this).addClass("selected");
                $ownHeight = $(this).height()/2;
                $("img#scroller").stop().animate({"top":$("div.selected").position().top+$ownHeight+"px"}, "slow");
                showChild($(this).index()-1);
                if ($('div.sharable').length != 0) {window.location.replace($(this).children('a').attr("href"));}
            }
        });
    }

    //HR APPLICATION
    function showContent(i,prev) {
        $("div.stepMenu div").removeClass("selected");
        $("div.stepMenu div:eq("+i+")").addClass("selected");
        $("div.content").children("form").children("div").css({"display":"none"});
        $("div.content").children("form").children("div:eq("+i+")").css({"display":"block"});
        $ownHeight = $("div.selected").height()/2;
        $("img#scroller").stop().animate({"top":$("div.selected").position().top+$ownHeight+"px"}, "slow");
        /*
        if (onStep>i) {
            onStep=i;
            $("div.stepMenu div").removeClass("unlocked");
            $("div.content div button").each(function() {
                if (($(this).attr("class")-1)<=i) {$("div.stepMenu div:eq("+($(this).attr("class")-1)+")").addClass("unlocked");}
            });
            Cufon.refresh('div.left-side div.steps h2');
        }
        */
        $div = $("div.content").children("form").children("div:eq("+prev+")");
        if (prev==0 || prev==1 || prev==2 || prev==7) $div = $div.children("div");
        if (prev==3 || prev==4 || prev==5 || prev==6) $div = $div.children("fieldset").children("div");
        $div.children("input,textarea").each(function() {
            if (($(this).attr("type") != "radio" && $(this).val().length > 0 && prev!=0) ||
                ($(this).attr("type") == "checkbox" && $(this).parent().children("input:checked").length > 0)) {
                $("div.stepMenu div:eq("+prev+")").addClass("filled");
                Cufon.refresh('div.left-side div.steps h2');
                return false;
            } else {
                if ($("div.stepMenu div:eq("+prev+")").hasClass("filled")) {
                    $("div.stepMenu div:eq("+prev+")").removeClass("filled");
                    Cufon.refresh('div.left-side div.steps h2');
                }
            }
        });
        onStep = i;
    }
    /*
    function goToStep(j) {
        onStep++;
        $("div.stepMenu div:eq("+j+")").addClass("unlocked");
        Cufon.refresh('div.left-side div.steps h2');
        showContent(j);
    }
    */
    if ($('div.steps').length != 0) {
        showContent(0);
        var onStep = 0;
        if ($("input#postcvresult").length != 0) {
            $("div.content").children("div").css({"display":"none"});
            $("form#application-form").css({"display":"none"});
            $("div.right-side div.content").append('<div class="form-message job"><p><b>'+JOBAPPLICATIONFORM+'</b><br />'+$("input#postcvresult").val()+'</p><a class="cvapp">'+aclose+'</a></div>');
            //$("input#postcvresult").remove();
        }
        $("div.stepMenu div").click(function(){
            //if (!$(this).hasClass('selected') && $(this).hasClass('unlocked')) {
            if (!$(this).hasClass('selected')) {
                showContent($(this).index(),onStep);
            }
        });
        var inputcount = 1;
        $("div.content form div a.additem,div.content form div a.additem-en").click(function(){
            $en = "";
            if ($(this).hasClass("additem-en")) {$en = "-en";}
            switch ($(this).attr("class")) {
                case "additem"+$en+" school":
                    $(this).before($("div.form-templates").clone().children("fieldset:eq(0)"));
                    break;
                case "additem"+$en+" language":
                    $(this).before($("div.form-templates").clone().children("fieldset:eq(1)"));
                    break;
                case "additem"+$en+" experience":
                    inputcount++;
                    $(this).before($("div.form-templates").clone().children("fieldset:eq(2)"));
                    $("input[name=experience-startdate[]]:eq("+inputcount+")").mask("99/9999");
                    $("input[name=experience-enddate[]]:eq("+inputcount+")").mask("99/9999");
                    break;
                default:
                    $(this).before($("div.form-templates").clone().children("fieldset:eq(3)"));
            }
        });
        $("div.content form div a.nextstep,div.content form div a.nextstep-en").click(function(){
            //goToStep($(this).attr("class"));
            showContent($(this).attr("rel"),onStep);
        });
    }

    if ($('div.extraitemline').length != 0) {
        $("a.additem,a.additem-en").click(function(){
           $(this).parent("div").before($("div.form-templates").clone().children("fieldset."+$(this).attr("id")).html());
        });
    }

    //CONTENT IMAGE NAVIGATIONS
    if ($('div.largeImage').length != 0 && $('div.largeImage ul > li').size() > 1) {
        //$(".largeImage").easySlider();
        $(".largeImage").children('ul').fadingbox();
        $("div.largeImage li").hover(function() {
            $(this).children("a").css({"display":"block"});
        },function() {
            $(this).children("a").css({"display":"none"});
        });
    }
    if ($('div.smallImage').length != 0 && $('div.smallImage ul > li').size() > 1) {
        //$(".smallImage").easySlider();
        $(".smallImage").children('ul').fadingbox();
        $(".smallImage").each(function(){
            //$("div.control a").css({"margin-top":"131px"});
            $(this).siblings("div.control").children('a').css({"margin-top":"131px"});
            //$("div#prevBtn").css({"margin-left":"255px"});
            //$("div#nextBtn").css({"right":"22px"});
            $(this).siblings(".prevBtn").css({"margin-left":"255px"});
            $(this).siblings(".nextBtn").css({"right":"22px"});
        });
        $("div.smallImage li").hover(function() {
            $(this).children("a").css({"display":"block"});
        },function() {
            $(this).children("a").css({"display":"none"});
        });
    }

    //CONTENT ACCORDION
    if ($('div.content div.accordionMenu').length != 0) {
        $('div.content .accordionContent').hide();
        $('div.content .accordionButton:first').addClass('on');
        $('div.content .accordionButton:first').next().slideDown('normal');
        $('div.content .accordionButton').click(function() {
            if (!$(this).hasClass('on')) {
                $('div.content .accordionButton').removeClass('on');
                $('div.content .accordionContent').slideUp('normal');
                if($(this).next().is(':hidden') == true) {
                    $(this).addClass('on');
                    $(this).next().slideDown('normal',function() {$("div.line").css({"height":$(this).parents(".accordionMenu").height()+"px"});});
                }
            }
        });
        if ($('div.line').length != 0) {
            $("div.line").myTimer(500,function(){
                $("div.line").css({"height":$("div.content div#TwoColumnContentAccordion div.accordionMenu").height()+"px"});
            });
        }
    }

    //EVENTS
    $("div.artwork").click(function() {
        if (!$(this).hasClass('on')) {
            $("div.on").removeClass("on").children("p").slideUp("fast");
            $(this).addClass("on").children("p").slideDown("fast");
        }
    });

    //CONTACT FORM
    if ($.browser.msie) {
        $('input[type=text],input[type=password],textarea').not(".error").focus(function() {
            $(this).css({"border-color":"#aeefff"});
        });
        $('input[type=text],input[type=password],textarea').not(".error").blur(function() {
            $(this).css({"border-color":"#fff"});
        });
    }
    function limitChars(textid, limit, infodiv) {
        var text = $('textarea#'+textid).val();
        var textlength = text.length;
        if(textlength > limit) {
            $('textarea#'+ textid).val(text.substr(0,limit));
            return false;
        } else
            {
            $('span.' + infodiv).html(limit - textlength);
            return true;
        }
    }
    $('textarea#message').keyup(function(){
        limitChars('message', 500, 'characterLeft');
    });

    //FORM MESSAGE
    $('div.form-message a').live('click', function() {
        if ($(this).hasClass("cvapp")) {
            $(this).parent().remove();
            $("form#application-form").css({"display":"block"});
            showContent(0);
            onStep = 0;
        } else {
            $i = $("div.tabMenu div.selected").index();
            $(this).parent().siblings("div:eq("+$i+")").css({"display":"block"});
            $(this).parent().remove();
        }
    });
    

    //SEARCH PAGE
    $("ol.results img").each(function() {
        $(this).css({"margin-left":432-($(this).width()/2)+"px"});
    });
    $("ol.results li").click(function() {
        window.location.replace($(this).children('a').attr("href"));
    });

    //GALLERY PAGE
    $("div.gallery div").click(function() {
        window.location.replace($(this).children('a').attr("href"));
    });
    
    //MAINPAGE NEWSLETTER SUBSCRIPTION
     $('#newsletterfrm').validate({
        rules: {
            "newsletter-mail": {
                email: true,
                required: true
            }
        },
        errorPlacement: function(error, element) {
            $("div.tip-box-c").html('<span class="error">'+invalidemail+'</span>');
            arrowPosition();
            $("div#newsletter input[type=text]").focus();
            //error.appendTo( element.parent("div").prev("span") );
        },
        submitHandler: function(form) {
            $('#realemail').val($("div#newsletter input[type=text]").val());
            $('#realnewsletterform').submit();
        }
    });
    
    $('#newsletter-submit').click(function(){
        $(this).parent().triggerHandler('submit');
            /*
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'newsletter', email: $('#newsletter-mail').val(), category: "1,2,3,4,5,6,7,8", registered: 0},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    var result = "error";
                    if (data.success) {result = "success";$("div#newsletter input[type=text]").attr({"value":""});}
                    $msg = eval(data.message);
                    $("div.tip-box-c").html('<span class="'+result+'">'+$msg+'</span>');
                    arrowPosition();
                    $("div#newsletter input[type=text]").focus();
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.tip-box-c").html('<span class="error">'+unexpectederror+'</span>');
                    arrowPosition();
                    $("div#newsletter input[type=text]").focus();
    	        }
    	    });
    	    return false;
            */
    });
    

    //CONTACT PAGE NEWSLETTER FORM
    $("#newsletter-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        submitHandler: function(form) {
            var fields = $("input[name='category']").serializeArray();
            if (fields.length == 0) {
                $("span.checkbox-check").html('<span class="error">'+mustselectatleastonesubj+'</span>');
            } else {
                $("span.checkbox-check").html("");
                var selectedCategories = "";
                $("input[name='category']:checked").each(function() {
                    selectedCategories += $(this).val()+",";
                });
                //selectedCategories = selectedCategories.substring(0, selectedCategories.length-1);
                $.ajax({
                    type: 'POST',
                    url: '/Process.php',
                    data: {op: 'newsletter', email: $('#mail-to-subscribe').val(), category: selectedCategories, registered: 0},
                    dataType: 'json',
                    cache: true,
                    success: function(data) {
                        if (data.success) {
                            $("div.right-side div.content").append('<div class="form-message"><p><b>'+newsletterform+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                            $('div.form-message').siblings("div").css({"display":"none"});
                            $("#newsletter-form input[type=text]").val("");
                        } else {
                            $("div.right-side div.content").append('<div class="form-message"><p><b>'+newsletterform+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                            $('div.form-message').siblings("div").css({"display":"none"});
                        }
                    },
                    error: function(xhr, status, error) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+newsletterform+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
                });
                return false;
            }
        }
    });

    //REGISTERED USER'S NEWSLETTER FORM
    $("#newslettersettings-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        submitHandler: function(form) {
            $("span.checkbox-check").html("");
            var selectedCategories = "";
            $("input[name='category']:checked").each(function() {
                selectedCategories += $(this).val()+",";
            });
            selectedCategories = selectedCategories.substring(0, selectedCategories.length-1);
            $.ajax({
                type: 'POST',
                url: '/Process.php',
                data: {op: 'newsletter', email: '', category: selectedCategories, registered: 1},
                dataType: 'json',
                cache: true,
                success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+NEWSLETTERSETTINGS+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    } else {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+NEWSLETTERSETTINGS+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
                },
                error: function(xhr, status, error) {
                    $("div.right-side div.content").append('<div class="form-message"><p><b>'+NEWSLETTERSETTINGS+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
                }
            });
            return false;
        }
    });

    //CONTACT FORM
    $("#contact-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        submitHandler: function(form) {
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'contactmail', name: $('input#name').val(),  mail: $('input#mail').val(), subject: $('input#subject').val(), message: $('textarea#message').val()},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+CONTACTFORM+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                        $("#contact-form input[type=text],#contact-form textarea").val("");
                    } else {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+CONTACTFORM+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.right-side div.content").append('<div class="form-message"><p><b>'+CONTACTFORM+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
    	        }
    	    });
    	    return false;
        }
    });

    //MEDIA RELATIONS PAGE PRESS RELEASE FORM
    $("#press-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        rules: {
            name: {
                required: true
            },
            address: {
                required: true
            },
            cellphone: {
                digits: true,
                minlength: 7
            },
            "extracellphone[]": {
                digits: true,
                minlength: 7
            },
            phone: {
                required: true,
                digits: true,
                minlength: 7
            },
            mail: {
                required: true,
                email: true
            },
            interests: {
                required: true
            },
            corporation: {
                required: true
            },
            category: {
                required: true
            },
            service: {
                required: true
            },
            jobtitle: {
                required: true
            }
        },
        submitHandler: function(form) {
            var extraCellPhoneVal = '';
            $("input.extracellphone").each(function() {
                var thisVal = $(this).val();
                if (thisVal!='') {
                    extraCellPhoneVal = extraCellPhoneVal + $(this).val()+',';
                }
            });
            extraCellPhoneVal = extraCellPhoneVal.substring(0,extraCellPhoneVal.length-1);
            var extraCorporationVal = '';
            $("input.extracorporation").each(function() {
                var thisVal = $(this).val();
                if (thisVal!='') {
                    extraCorporationVal = extraCorporationVal + $(this).val()+',';
                }
            });
            extraCorporationVal = extraCorporationVal.substring(0,extraCorporationVal.length-1);
        	var pinterests = $("input:checked[name=interests]").map(function() {return $(this).val();}).get().join();
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'pressreleaseregister',name: $('input#pname').val(), corporation: $('input#pcorporation').val(), category: $('select#pcategory').val(),period: $('select#pperiod').val(), service: $('input#pservice').val(), jobtitle: $('input#pjobtitle').val(), address: $('textarea#paddress').val(), phone: $('input#pphone').val(),cellphone: $('input#pcellphone').val(), extracellphone: extraCellPhoneVal, extracorporation: extraCorporationVal, mail: $('input#pmail').val(),interests:pinterests},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+PRESSRELEASEREGFORM+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                        $("#press-form input[type=text],#press-form textarea").val("");
                    } else {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+PRESSRELEASEREGFORM+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.right-side div.content").append('<div class="form-message"><p><b>'+PRESSRELEASEREGFORM+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
    	        }
    	    });
    	    return false;
        }
    });

    //REGISTER FORM    
    $("#register-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        rules: {
            password: {
                rangelength: [4, 12]
            },
            passwordrepeat: {
                equalTo: "#rpassword"
            },
            mailrepeat: {
                equalTo: "#rmail"
            }
        },
        submitHandler: function(form) {
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'registeruser', firstname: $('input#rfirstname').val(),  lastname: $('input#rlastname').val(), mail: $('input#rmail').val(), password: $('input#rpassword').val()},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+REGISTRATIONFORM+'</b><br />'+eval(data.message)+'<br />'+redirectinseconds+'</p></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                        $('div.content').myTimer(3000,function(){
                            window.location.href="/"+langcode;
                        });
                    } else {
                        $('div.content div h1').after('<span class="sp-error">'+eval(data.message)+'</span>');
                    }
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.right-side div.content").append('<div class="form-message"><p><b>'+REGISTRATIONFORM+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
    	        }
    	    });
    	    return false;
        }
    });

    //CHANGING PROFILE INFO
    $("#profilechange-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        submitHandler: function(form) {
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'changeprofile', firstname: $('input#pfirstname').val(),  lastname: $('input#plastname').val()},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+PROFILEINFO+'</b><br />'+eval(data.message)+'</p><a'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    } else {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+PROFILEINFO+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.right-side div.content").append('<div class="form-message"><p><b>'+PROFILEINFO+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
    	        }
    	    });
    	    return false;
        }
    });

    //CHANGING PASSWORD
    $("#changepass-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        rules: {
            oldpassword: {
                required: true,
                rangelength: [4, 12]
            },
            newpassword: {
                required: true,
                rangelength: [4, 12]
            },
            newpasswordrepeat: {
                required: true,
                rangelength: [4, 12],
                equalTo: "#cnewpassword"
            }
        },
        submitHandler: function(form) {
            $.ajax({
    	        type: 'POST',
    	        url: '/Process.php',
    	        data: {op: 'changepass', oldpass: $('input#coldpassword').val(),  newpass: $('input#cnewpassword').val()},
    	        dataType: 'json',
    	        cache: true,
    	        success: function(data) {
                    if (data.success) {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+CHANGINGPASSWORD+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $("#changepass-form input[type=password]").val("");
                        $('div.form-message').siblings("div").css({"display":"none"});
                    } else {
                        $("div.right-side div.content").append('<div class="form-message"><p><b>'+CHANGINGPASSWORD+'</b><br />'+eval(data.message)+'</p><a>'+aclose+'</a></div>');
                        $('div.form-message').siblings("div").css({"display":"none"});
                    }
    	        },
    	        error: function(xhr, status, error) {
    	        	$("div.right-side div.content").append('<div class="form-message"><p><b>'+CHANGINGPASSWORD+'</b><br />'+unexpectederror+'</p><a>'+aclose+'</a></div>');
                    $('div.form-message').siblings("div").css({"display":"none"});
    	        }
    	    });
    	    return false;
        }
    });
    
    //APPLICATION FORM
    $("#ahomephone,#acellphone").mask("(999) 999 99 99");
    $(".jobdate").mask("99/9999");
    var firsterror = 0;
    $("#application-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
            if (firsterror == 0) {
                if (element.parent("div").parent("fieldset").length != 0) {$errorSection = element.parent("div").parent("fieldset").parent("div");}
                else {$errorSection = element.parent("div").parent("div");}
                $firstelementIndex = $errorSection.index();
                $("span.mainerror").html(errorsfound);
                showContent($firstelementIndex-1,$firstelementIndex-2);
                firsterror = 1;
            }
        },
        rules: {
            "positions-position[]": {
                required: true
            },
            "personalinfo-firstname": {
                required: true
            },
            "personalinfo-lastname": {
                required: true
            },
            "personalinfo-sex": {
                required: true
            },
            "personalinfo-idnumber": {
                required: true,
                digits: true,
                minlength: 11,
                maxlength: 11
            },
            "personalinfo-marital": {
                required: true
            },
            "contactinfo-address": {
                required: true
            },
            "contactinfo-mail": {
                required: true,
                email: true
            },
            "contactinfo-homephone": {
                required: true
            },
            "contactinfo-cellphone": {
                required: true
            },
            "contactinfo-other": {
                digits: true,
                minlength: 7
            },
            "additionalinfo-question1": {
                required: true
            },
            "additionalinfo-question2": {
                required: true
            },
            "additionalinfo-question3": {
                required: true
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
    if ($("input.referencephone").length != 0) {
        $("input.referencephone").each(function(){
            $(this).rules("add", {
                digits: true,
                minlength: 7
            });
        });
    }
    if ($("#aschool").length != 0) {$("#aschool").rules("add", {required: true});}
    if ($("#adepartment").length != 0) {$("#adepartment").rules("add", {required: true});}
    if ($("#agradyear").length != 0) {$currentyear = $("input#currentyear").val();$("#agradyear").rules("add", {required: true, digits: true, minlength: 4, range: [1940, $currentyear]});}

    //ACCREDITATION FORM
    $("#accreditation-form").validate({
        errorPlacement: function(error, element) {
            error.appendTo( element.parent("div").prev("span") );
        },
        rules: {
            accname: {
                required: true
            },
            accmail: {
                required: true,
                email: true
            },
            accfile: {
                required: true
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });

    $(".contact-forms input[type=button]").click(function() {
        $form = $(this).parent();
        if ($(this).attr("id")=="application-submit") {$form = $(this).parent().parent();firsterror = 0;}
        $form.triggerHandler('submit');
    });

    //jQuery('#searchform').attr('action',jQuery('#searchform').attr('action')+'/'+jQuery('#searchkeyword').val());jQuery('#searchform').submit();
    $("#search-submit").click(function() {
    	$('#searchform').attr('action',$('#searchform').attr('action')+'/'+$('#searchkeyword').val());
        $("#searchform").submit();
    });
    if ($("span.formtooltip").length != 0) {
        var startvalue = new Array();
        $("span.formtooltip").each(function() {
            startvalue[$(this).attr('id')] = $(this).html();
            $(this).html("");
        });
        $("img.formtooltip").hover(function() {
            $(this).next().css({"background-color":"#999"}).html(startvalue[$(this).next().attr('id')]);
        },function() {
            $(this).next().css({"background-color":"transparent"}).html("");
        });
    }
    if ($("div.flash").length != 0 && $.browser.msie) {
        //$("div.flash").children().hide();
    }

    if ($('#musicPlayer').lenght != 0) {
		var flashvars = {
		};
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			bgcolor: "#FFFFFF"
		};
		var attributes = {
			id:"musicPlayer"
		};
		swfobject.embedSWF("soundPlayer.swf", "musicPlayer", "210px", "25px", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
    }

});

$(window).resize(function() {
    IKSV.share.email.relocate();
});
